Date post: | 12-Dec-2015 |
Category: |
Documents |
Upload: | tristan-tubb |
View: | 213 times |
Download: | 0 times |
V 1.0
Sch
ed
ule
(Lesson
s)
OE NIK, 2014 2
1 Expectations, HTML Intro
2 Control Structures
3 Array, Strings, Calculators
4 File management, Guestbook
5 Session storage, Login
6 Forum
7 TEST 1
8 PHP+SQL basic usage
9 CRUD 1
10 CRUD 2 (??? TDK ???)
11 CMS
12 TEST 2
13 ExtraZH / Project Presentation
V 1.0
Sch
ed
ule
(H
om
ew
ork
s)
OE NIK, 2014 3
1
2
3
4 THEOREMS HW request (for points in test 1)
5
6 THEOREMS HW deadline
7
8 TOPIC + ER request
9 TOPIC + ER deadline, DB + ACTION PLAN request
10
11 DB + ACTION PLAN deadline
12
13PROJECT+PROJECT DOCS DEADLINE (.FR)OTHERS: IN EXAM
V 1.0
WARNING• A small level of HTML/SQL and basic programming
knowledge is presumed. Otherwise, you’ll need extra time of preparation on your own!
• 3 ECTS = 3*30 hours = 90 hours
• 13*3*45 minutes = 1755 minutes = 30 hours
• That means 60 hours of work AT HOME
• ~20 hours of preparation before the 1st test, ~20 hours of preparation before the 2nd test, ~20 hours of preparation for the project
4OE NIK 2013
V 1.0
Expectations
• Two tests within the semester– 1. PHP basic structures and algorithms– 2. PHP+MySQL CRUD + Query exercises
(extra points are calculated into the second test)
• Project exercise:– A custom management interface for anything you
want– At least 3 tables (connector tables not included)– Not advised: a book/dvd/vhs rental webpage– Authentication (guest/not-logged-in + admin)
required, authorization/rbac is not– Aim for total HTML/PHP separation 5OE NIK, 2014
V 1.0
Project
• Create database that can be used with the PHP project:– Choose a topic– Create ER diagram to plan the data (at least three
inter-connected entities)– Create the table structure diagram
6OE NIK, 2014
V 1.0
Project• Documentation
– Task description– Diagrams / Database description– "Action plan"– Description of noteworthy algorithms– Only in PDF!
• Source code– Full PHP/HTML/CSS/SQL source– Students will be asked to write small add-ons for
the given project
7OE NIK, 2014
V 1.0
Project• Everything must be sent in email, compressed into
ZIP/ARJ/RAR/7Z/GZ/BZ format• [email protected] , use [PHP] in the
subject!• Deadline: the day before the presentation, MIDNIGHT
• Presentation:– For French students: presentation MUST BE on the
last lesson (? 13rd of May)– For other students: presentation can be on any of
the exam dates, or during the last lesson (13th of May, only if both tests are successful)
8OE NIK, 2014
V 1.0 OE NIK, 2014 9
PHP+SQL1.
HTML IntroductionHTML RenderingHTML TagsCSS, JSExamples
(source: w3schools.com)
V 1.0
MVC• Model – View –
Controller: separated layers
• HTML: format to describe content shown in browsers
• HTML3: content + style together
• HTML4: mixed (chaos)• HTML5: only content +
CSS: style „The Right Way” 11OE NIK, 2014
V 1.0
HTML
• HTML is used to describe the content of webpages• HTML = Hyper Text Markup Language • HTML is NOT a programming language, but it is a
markup language • A markup language's tokens are markup tags, the
different language's are different in the possible tags and the different rules and restrictions: XML , SGML, HTML, SVG
12OE NIK, 2014
V 1.0
HTML
• The HTML tags are sorrounded by < and > letters, e.g. <html> (which marks the starting point of the document)
• The HTML tags usually come in pairs, like <html> and </html> (starting and end point of the document, opener and closer tags)
• Comments: <!-- -->• Most of the HTML tags can include other HTML tags
and/or attributes (inline vs. block elements)• <head>: Meta tags (invisible content) SEO,
Pagerank• <body>: Displayed content
13OE NIK, 2014
V 1.0
HTML<html><head> <title>Page title</title> </head>
<body><h1>My First Heading</h1><p>My first paragraph</p>
<a href="http://www.w3schools.com">This is a link</a>
<br ><img src="w3schools.jpg" width="104" height="142"> <hr/></body></html>
14OE NIK, 2014
V 1.0
HTML• HTML entity: &entity_name; OR &#entity_number;
– < > & ©• References:
– Absolute (<img src=‘/path/to/file.jpg’>)– Relative (<img src=‘path/to/file.jpg’>)– External (using protocol definition) (<img
src=‘http://index.hu/path/file.jpg’>)– The trailing slash can be important: <a
href=‘path/to/dir’> vs <a href=‘path/to/dir/’> small things can affect the performance
15OE NIK, 2014
V 1.0
HTML
• HTML vs. XHTML: different level of strictness, different complexity and behavior of the browser (XHTML is better and simpler to render – documents are not expected to be valid now [valid vs. well-formed])
• There are several approaches and ways to do the same thing (e.g. align to center: HTML3: <center> HTML4: <p align=‘center’> <p style=‘text-align:center’> HTML5: ONLY style/CSS)
• Various browsers interpret and implement the standards in different ways ???
16OE NIK, 2014
V 1.0
ACID2 (2005) and the browsers• Safari 2.0.2 (Webkit, 31/OCT/2005), Konqueror 3.5
(KHTML, 29/NOV/2005), Chrome 1 (Webkit/KHTML, 11/DEC/2008)
• Opera 9 (Presto, 20/JUN/2006)• FF3 (Gecko, 17/JUN/2008)• IE8 (Trident, 19/MAR/2009)
21OE NIK, 2014
V 1.0
ACID3 (2008) and the browsers• Safari 4 (8/JUN/2009), Chrome 4 (25/JAN/2010)• Opera 10 (01/SEP/2009)• FF4 (22/MAR/2011)• IE8 (20/100), IE9 beta: 32/100 (18/NOV/2009) , 95/100
(04/AUG/2010)• IE9: 17/SEP/2011 (100 points, but incorrect shadow)
• From the browsers above, ONLY the Webkit-based browsers (Chrome, Safari, Epiphany/WEB) fulfill the performance requirement (continous animation without breaks and stops)
23OE NIK, 2014
V 1.0
ACID4?
• More SVG, CSS3; less JS• Multicol layout, special backgrounds (e.g.
transients, background-combinations)• Subpixel/Sub-line accuracy WaSP dismissed as of 2013, future doubtful...
What can we learn from the ACID tests: every browser ********!
But the user/client will NEVER blaim the browser, only the programmer…
It is not enough to know the standards, we must also be familiar with the browsers
24OE NIK, 2014
V 1.0
COLORS000000 000033 000066 000099 0000CC 0000FF
003300 003333 003366 003399 0033CC 0033FF
006600 006633 006666 006699 0066CC 0066FF
009900 009933 009966 009999 0099CC 0099FF
00CC00 00CC33 00CC66 00CC99 00CCCC 00CCFF
00FF00 00FF33 00FF66 00FF99 00FFCC 00FFFF
330000 330033 330066 330099 3300CC 3300FF
333300 333333 333366 333399 3333CC 3333FF
336600 336633 336666 336699 3366CC 3366FF
339900 339933 339966 339999 3399CC 3399FF
33CC00 33CC33 33CC66 33CC99 33CCCC 33CCFF
33FF00 33FF33 33FF66 33FF99 33FFCC 33FFFF
660000 660033 660066 660099 6600CC 6600FF
663300 663333 663366 663399 6633CC 6633FF
666600 666633 666666 666699 6666CC 6666FF
669900 669933 669966 669999 6699CC 6699FF
66CC00 66CC33 66CC66 66CC99 66CCCC 66CCFF
66FF00 66FF33 66FF66 66FF99 66FFCC 66FFFF
990000 990033 990066 990099 9900CC 9900FF
993300 993333 993366 993399 9933CC 9933FF
996600 996633 996666 996699 9966CC 9966FF
999900 999933 999966 999999 9999CC 9999FF
99CC00 99CC33 99CC66 99CC99 99CCCC 99CCFF
99FF00 99FF33 99FF66 99FF99 99FFCC 99FFFF
CC0000 CC0033 CC0066 CC0099 CC00CC CC00FF
CC3300 CC3333 CC3366 CC3399 CC33CC CC33FF
CC6600 CC6633 CC6666 CC6699 CC66CC CC66FF
CC9900 CC9933 CC9966 CC9999 CC99CC CC99FF
CCCC00 CCCC33 CCCC66 CCCC99 CCCCCC CCCCFF
CCFF00 CCFF33 CCFF66 CCFF99 CCFFCC CCFFFF
FF0000 FF0033 FF0066 FF0099 FF00CC FF00FF
FF3300 FF3333 FF3366 FF3399 FF33CC FF33FF
FF6600 FF6633 FF6666 FF6699 FF66CC FF66FF
FF9900 FF9933 FF9966 FF9999 FF99CC FF99FF
FFCC00 FFCC33 FFCC66 FFCC99 FFCCCC FFCCFF
FFFF00 FFFF33 FFFF66 FFFF99 FFFFCC FFFFFF
26OE NIK, 2014
V 1.0
HTML ATTRIBUTES
Attribute Value Description
class class_name The class of the element
id (vs. name)
id_name A unique id for the element
style style_definition An inline style definition
title tooltip_text A text to display in a tool tip
27OE NIK, 2014
V 1.0
HTML4 (HTML5)Tag Description
<b> Defines bold text ( strong)
<big> Defines big text ( style)
<em> Defines emphasized text
<i> Defines italic text ( em)
<small> Defines small text ( style)
<strong> Defines strong text
<sub> Defines subscripted text
<sup> Defines superscripted text
<ins> Defines inserted text
<del> Defines deleted text ( strike)
<u> Underlined ( style)
28OE NIK, 2014
V 1.0
LISTS
<ul> <li>Coffee</li> <li>Milk</li></ul>
<ol> <li>Coffee</li> <li>Milk</li></ol>
<dl> <dt>Coffee</dt> <dd>Black hot drink</dd> <dt>Milk</dt> <dd>White cold drink</dd></dl>
29OE NIK, 2014
V 1.0
Tag Description
<form> Defines a form for user input
<input> Defines an input field
<textarea> Defines a text-area (a multi-line text input control)
<label> Defines a label to a control
<fieldset> Defines a fieldset
<legend> Defines a caption for a fieldset
<select> Defines a selectable list (a drop-down box)
<option> Defines an option in the drop-down box
<button> Defines a push button30OE NIK, 2014
V 1.0
FORMS<form>First name:<input type="text" name="firstname" /><br />Last name:<input type="text" name="lastname" /></form>
<form><input type="radio" name="sex" value="male" /> Male<br /><input type="radio" name="sex" value="female" /> Female</form>
31OE NIK, 2014
V 1.0
FORMS
<form>I have a bike:<input type="checkbox" name="haveBike" value="Bike" /><br />I have a car:<input type="checkbox" name="haveCar" value="Car" /><br />I have an airplane:<input type="checkbox" name="haveAirplane" value="Airplane" /></form>
32OE NIK, 2014
V 1.0
FORMS
<form>I have a bike:<input type="checkbox" name="vehicle[]" value="Bike" /><br />I have a car:<input type="checkbox" name="vehicle[]" value="Car" /><br />I have an airplane:<input type="checkbox" name="vehicle[]" value="Airplane" /></form>
33OE NIK, 2014
V 1.0
FORMS
<form>I have a:<select name='vehicle'>
<option value='bike'>Bicycle</option><option value='car'>Shiny shiny car</option><option value='airplane'>Flying airplane</option>
</select></form>
34OE NIK, 2014
V 1.0
FORMS
<form name="input" action="submit.php" method="GET">Username:<input type="text" name="user" /><input type="submit" value="Submit" /></form>
GET vs POSTHTTP vs HTTPSID vs name
35OE NIK, 2014
V 1.0
TABLES
Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<col> Defines the attribute values for one or more columns in a table
<thead> Defines a table head
<tbody> Defines a table body
<tfoot> Defines a table footer
36OE NIK, 2014
V 1.0
TABLES
<table border="1"><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>
<table border="1"><tr><td>row 1, cell 1</td><td colspan=‘2’>cell 2</td></tr><tr><td>row 2, cell 1</td></tr></table>
37OE NIK, 2014
V 1.0
THE GOD OF <DIV>
• Easier to design/change• Easier to separate the style and the content using CSS• By default a block-level element, but this can be changed• float: none, left, right• clear:both• THE MOST IMPORTANT HTML TAG! 39OE NIK, 2014
V 1.0
STYLE (only copypaste into project)• HTML3: several tags to affect the style, HTML4: those
tags are now deprecated• HTML5: those tags are now removed, ONLY CSS AND
THE STYLE ATTRIBUTE should be used!• We will not explicitly use HTML5, but tags (<center>,
<b>, <u>) and attributes (align, color, bgcolor) that affect the look of a page are discouraged
• Rules for tag, class, id
style="text-align:center; font-weight: bold; font-decoration: underline; color: white; background-color: green; font-family: Times; font-size: 10px” 41OE NIK, 2014
V 1.0
STYLE
• <link rel="stylesheet" type="text/css" href="mystyle.css">
• <style type="text/css">body { background-color: red }p { margin-left: 20px }</style>
• <p style="color: red; margin-left: 20px">This is a paragraph</p>
42OE NIK, 2014
V 1.0
CSS BOX MODEL• Weakly supported in the beginning (especially IE5,
IE6, IE7 (till 2009)), multiple CSS files were used• The new IE versions are a lot better, de pixel-correct
webpages are difficult to create• Less, Sass, Stylus
43OE NIK, 2014
V 1.0
Practical example ...• Instead of small CSS/HTML snippets …• Create a checkerboard – ONLY HTML+CSS (no js or
images)• Aim: smallest possible size
OE NIK, 2014 44
V 1.0
JAVASCRIPT (not required at all)
• Clientside program (executed by the browser):
<html><body>
<script type="text/javascript">document.write("Hello World!")</script>
</body></html>
50OE NIK, 2014
V 1.0
EVENTSAttribute Value Description
onchange script Script to be run when the element changes
onsubmit script Script to be run when the form is submitted
onclick script What to do on a mouse click
onkeydown script What to do when key is pressed
onkeypress script What to do when key is pressed and released
onkeyup script What to do when key is released
51OE NIK, 2014
V 1.0
DOM ELEMENT ACCESS
• document.name vs document.getElementById()• var obj=document.getElementById(‘xxx’);
obj.style.display=‘none’;• The commands and properties are now more or less
the same• Huge differences in the performance
(chrome++, IE--)
• Old technology, almost extinct AJAX !!!• Frameworks: jQuery, prototype, mootools, YUI, ExtJS
… Gnome and Win7 widgets?!?!?!?!?!
52OE NIK, 2014
V 1.0
TYPING• Weakly/loosely/dynamically-typed languagefunction wl(what){
document.write(what);document.write("<hr>");
}var a=5; wl(a);var b=a+5; wl(b);var b=b+"5"; wl(b);var c=function(){ alert("HELLO"); }; wl(c); c();var d=b+c; wl(d);var e=parseInt(d); wl(e);
OE NIK, 2014 53
V 1.0
SELF REFERENCINGvar obj = { a: 5, b: 6, arr: [4, 5, 6, 7], str: "Bela", init: function() { this.c = this.a + this.b; return this; }}.init();wl(obj.str); wl(obj.c);
OE NIK, 2014 54
V 1.0
REVEALING MODULE PATTERN• Lack of proper OOP in JS• Workarounds: Prototype inheritance, Revealing pattern
OE NIK, 2014 55
V 1.0
REALTIME ASYNC COMMUNICATION• Not possible in original HTTP• Many possible workarounds
– Forever Frame (push into hidden iframe)– AJAX, Long polling– Server Sent Events (EventSource, not in IE)– WebSockets
• Possible alternative: SignalR in .NET – uses WebSockets, fallbacks to other solutions in case of failure
• We write too much javascript code, browsers are different, implementations are different… We need a soluton!
OE NIK, 2014 56
V 1.0
jQuery• „Write Less, Do More”• Main features:
– Normalize vendor-specific javascript language elements (e.g. e.which, e.keycode)
– Use CSS (and CSS-like) selectors to specify target element(s): tag, class, id, :even, :not, [attr=val]
– Define events/execute code for target element(s) – Chain up multiple operations for same element(s)– Easier AJAX manipulation
OE NIK, 2014 57
V 1.0
jQuery example• Instead of simple snippets… Let’s build a tree!• Typical task: menus, toolbars, structured multi-level lists
OE NIK, 2014 58
V 1.0
Problems with trees• Typical solution from programs is using recursion or sql
CONNECT BY/WITH• We do not like recursion… • CONNECT BY is not supported by mysql, for example
(and the syntax of the WITH clause is horrific)• Finding errors in a recursive function or a recursive html
element is hard• Alternative solution
– Build the tree as a sequential list from DIVs– Every div should have two attributes: ID and PARENT– Additionally: NAME and CONTENT– Loop through the list using jQuery, build the tree in
the browser OE NIK, 2014 59
V 1.0
Style.tree_wrapper {
min-height: 50px;border: 1px dotted gray;background-color: #ddd;
}.tree_elem {
padding-left: 20px;min-height: 50px;border: 1px dotted gray;background-color: #eee;
}
OE NIK, 2014 60
.tree_over { background-color:#fff;}.hidden { display:none;}
V 1.0
Set-Upfunction myscroll(){ $('html, body').animate( { scrollTop: $(".tree_clicked")
.offset().top-20}, 800);
}$(window).load(function(){
$(".tree_wrapper").mouseover(function(){$(this).addClass("tree_over");
}).mouseout(function(){$(this).removeClass("tree_over");
});});
OE NIK, 2014 61
V 1.0
Algorithm• $(window).load(function(){
Loop Through Every Node, put to its good locationShow initialized state of the treeIF we click on a tree element
Hide all tree partsShow sub-tree for clicked elementShow root elementsScroll to clicked element
IF ends});
OE NIK, 2014 62
V 1.0
Loop Through Every Node, initializevar nums=new Array();$("#treediv").children().each(function(index, element){
// OR: We could use .attr()var parentid=$
(element).children(".tree_parentid").first().html();var nodeid=$
(element).children(".tree_nodeid").first().html();$(element).detach();$("#subtree_"+parentid).append($(element));if (nums[parentid] == null) nums[parentid]=0;nums[parentid]++;$("#subnumber_"+nodeid).html(0);$("#subnumber_"+parentid).html(nums[parentid]);
});$(".tree_elem").hide();$(".parent_0").show();
OE NIK, 2014 63
V 1.0
When we click… then, we should scroll …$('.tree_name')
.css("cursor", "hand")
.css("cursor", "pointer")
.click(function(obj){var $clicked_elem=$(this).parent(); $("#subtree_0")
.find('.tree_clicked')
.removeClass("tree_clicked");//$('.tree_clicked') vs find() vs children()
$clicked_elem.addClass("tree_clicked");
[... Show only good tree nodes ...]myscroll();
});OE NIK, 2014 64
V 1.0
Show only the good nodes$(".subtree").children(".tree_elem").hide();var num=0; var $akt_elem=$clicked_elem;do {
$akt_elem.children(".subtree").children(".tree_elem").show();
$akt_elem=($akt_elem.parent());num++;if (num==10) {
alert("ERROR: TOO DEEP WHILE CHAIN");return;
}} while ($akt_elem.attr('id')!="subtree_0");$(".parent_0").show();
OE NIK, 2014 65
V 1.0
EXERCISE• Let's create a basic HTML+CSS combination• Header: some image, Nav: Menu with links, Footer:
information about the creator, Main: Lorem ipsum
67OE NIK, 2014