1、深入 PHP 与 jQuery 开发源代码下载(Pro PHP and jQuery source code)看完这本书后觉得内容挺不错的,书中的代码基本上都能实现,为方便广大同仁更好的学习和参考,能以我个人的能力给大家做点贡献我也觉得非常荣幸,欢迎大家踊跃下载!本想免费供大家下载的,可是为了同时也能让我下载更多的学习资料,所以还是决定跟大家要点财富值吧,嘿嘿!下面是这个项目的目录结构!下面是运行效果图:首先是 app 目录下的 admin.php 文件, 代码如下:displayForm(); ?下面是 confirmdelete.php 文件:confirmDelete($id);/* O
2、utput the header*/$page_title = “View Event“;$css_files = array(“style.css“, “admin.css“);include_once assets/common/header.inc.php;?Index.phpbuildCalendar();?Login.phpPlease Log InUsernamePassword“ /or cancelView.phpdisplayEvent($id) ?Back to the calendar下面是 app 目录 assets 目录下文件:首先是 Commen 目录:Footer
3、.inc.phpheader.inc.php“ /Css 目录:Admin.cssfieldset border: 0;legend font-size: 24px;font-weight: bold;inputtype=text,inputtype=password,label display: block;width: 70%;font-weight: bold;textarea width: 99%;height: 200px;inputtype=text,inputtype=password,textarea border: 1px solid #123;-moz-border-rad
4、ius: 6px;-webkit-border-radius: 6px;border-radius: 6px;-moz-box-shadow: inset 1px 2px 4px #789;-webkit-box-shadow: inset 1px 2px 4px #789;box-shadow: inset 1px 2px 4px #789;padding: 4px;margin: 0 0 4px;font-size: 16px;font-family: georgia, serif;inputtype=submit margin: 4px 0;padding: 4px;border: 1p
5、x solid #123;-moz-border-radius: 6px;-webkit-border-radius: 6px;border-radius: 6px;-moz-box-shadow: inset -2px -1px 3px #345,inset 1px 1px 3px #BCF,1px 2px 6px #789;-webkit-box-shadow: inset -2px -1px 3px #345,inset 1px 1px 3px #BCF,1px 2px 6px #789;box-shadow: inset -2px -1px 3px #345,inset 1px 1px
6、 3px #BCF,1px 2px 6px #789;background-color: #789;font-family: georgia, serif;text-transform: uppercase;font-weight: bold;font-size: 14px;text-shadow: 0px 0px 1px #fff;.admin-options text-align: center;.admin-options form,.admin-options p display: inline;a.admin,a.linkdisplay: inline-block;margin: 4
7、px 0;padding: 4px;border: 1px solid #123;-moz-border-radius: 6px;-webkit-border-radius: 6px;border-radius: 6px;-moz-box-shadow: inset -2px -1px 3px #345,inset 1px 1px 3px #BCF,1px 2px 6px #789;-webkit-box-shadow: inset -2px -1px 3px #345,inset 1px 1px 3px #BCF,1px 2px 6px #789;box-shadow: inset -2px
8、 -1px 3px #345,inset 1px 1px 3px #BCF,1px 2px 6px #789;background-color: #789;color: black;text-decoration: none;font-family: georgia, serif;text-transform: uppercase;font-weight: bold;font-size: 14px;text-shadow: 0px 0px 1px #fff;Ajax.css.modal-overlay position: fixed;top: 0;left: 0;bottom: 0;width
9、: 100%;height: 100%;background-color: rgba(0,0,0,.5);z-index: 4;.modal-window position: absolute;top: 140px;left: 50%;width: 300px;height: auto;margin-left: -150px;padding: 20px;border: 2px solid #000;background-color: #FFF;-moz-border-radius: 6px;-webkit-border-radius: 6px;border-radius: 6px;-moz-b
10、ox-shadow: 0 0 14px #123;-webkit-box-shadow: 0 0 14px #123;box-shadow: 0 0 14px #123;z-index: 5;.modal-close-btn position: absolute;top: 0;right: 4px;margin: 0;padding: 0;text-decoration: none;color: black;font-size: 16px;.modal-close-btn:before position: relative;top: -1px;content: “Close“;text-tra
11、nsform: uppercase;font-size: 10px;Style.css body background-color: #789;font-family: georgia, serif;font-size: 13px;#content display: block;width: 812px;margin: 40px auto 10px;padding: 10px;background-color: #FFF;-moz-border-radius: 6px;-webkit-border-radius: 6px;border-radius: 6px;border:2px solid
12、black;-moz-box-shadow: 0 0 14px #123;-webkit-box-shadow: 0 0 14px #123;box-shadow: 0 0 14px #123;h2,p margin: 0 auto 14px;text-align: center;ul display: block;clear: left;height: 82px;width: 812px;margin: 0 auto;padding: 0;list-style: none;background-color: #FFF;text-align: center;border: 1px solid
13、black;border-top: 0;border-bottom: 2px solid black;li position: relative;float: left;margin: 0;padding: 20px 2px 2px;border-left: 1px solid black;border-right: 1px solid black;width: 110px;height: 60px;overflow: hidden;background-color: white;li:hover background-color: #FCB;z-index: 1;-moz-box-shado
14、w: 0 0 10px #789;-webkit-box-shadow: 0 0 10px #789;box-shadow: 0 0 10px #789;.weekdays height: 20px;border-top: 2px solid black;.weekdays li height: 16px;padding: 2px 2px;background-color: #BCF;.fill background-color: #BCD;.weekdays li:hover,li.fill:hover background-color: #BCD;-moz-box-shadow: none
15、;-webkit-box-shadow: none;box-shadow: none;.weekdays li:hover,.today background-color: #BCF;li strong position: absolute;top: 2px;right: 2px;li a position: relative;display: block;border: 1px dotted black;margin: 2px;padding: 2px;font-size: 11px;background-color: #DEF;text-align: left;-moz-border-ra
16、dius: 6px;-webkit-border-radius: 6px;border-radius: 6px;z-index: 1;text-decoration: none;color: black;font-weight: bold;font-style: italic;li a:hover background-color: #BCF;z-index: 2;-moz-box-shadow: 0 0 6px #789;-webkit-box-shadow: 0 0 6px #789;box-shadow: 0 0 6px #789;下面是 inc 目录:首先是 ajax.inc.php$
17、val )define($name, $val);$actions = array(event_view = array(object = Calendar,method = displayEvent),edit_event = array(object = Calendar,method = displayForm),event_edit = array(object = Calendar,method = processForm),delete_event = array(object = Calendar,method = confirmDelete),confirm_delete =
18、array(object = Calendar,method = confirmDelete);if ( isset($actions$_POSTaction) )$use_array = $actions$_POSTaction;$obj = new $use_arrayobject($dbo);if ( isset($_POSTevent_id) )$id = (int) $_POSTevent_id;else$id = NULL;echo $obj-$use_arraymethod($id);function _autoload($class_name)$filename = /syst
19、em/class/class. strtolower($class_name) . .inc.php;if ( file_exists($filename) )include_once $filename;?Process.inc.php$val )define($name, $val);$actions = array(event_edit = array(object = Calendar,method = processForm,header = Location: /),user_login = array(object = Admin,method = processLoginFor
20、m,header = Location: /),user_logout = array(object = Admin,method = processLogout,header = Location: /);/* Make sure the anti-CSRF token was passed and that the* requested action exists in the lookup array*/if ( $_POSTtoken=$_SESSIONtoken$obj = new $use_arrayobject($dbo);if (TRUE = $msg=$obj-$use_ar
21、raymethod()header($use_arrayheader);exit;elsedie ( $msg );else/ Redirect to the main index if the token/action is invalidheader(“Location: /“);exit;function _autoload($class_name)$filename = /system/class/class.strtolower($class_name) . .inc.php;if ( file_exists($filename) )include_once $filename;?下
22、面是 js 目录:Init.jsjQuery(function($)var processFile = “assets/inc/ajax.inc.php“,fx = “initModal“ : function() / If no elements are matched, the length/ property will return 0if ( $(“.modal-window“).length=0 )/ Creates a div, adds a class, and/ appends it to the body tagreturn $(“).hide().addClass(“mod
23、al-window“).appendTo(“body“);elsereturn $(“.modal-window“);,“boxin“ : function(data, modal)$(“).hide().addClass(“modal-overlay“).click(function(event)/ Removes eventfx.boxout(event);).appendTo(“body“);modal.hide().append(data).appendTo(“body“);/ Fades in the modal window and overlay$(“.modal-window,
24、.modal-overlay“).fadeIn(“slow“);,“removeevent“ : function()/ Removes any event with the class “active“$(“.active“).fadeOut(“slow“, function()$(this).remove(););,“boxout“ : function(event) / If an event was triggered by the element/ that called this function, prevents the/ default action from firingi
25、f ( event!=undefined )event.preventDefault();/ Removes the active class from all links$(“a“).removeClass(“active“);/ Fades out the modal window, then removes/ it from the DOM entirely$(“.modal-window,.modal-overlay“).fadeOut(“slow“, function() $(this).remove(););,“addevent“ : function(data, formData
26、)/?-?|?2?a?1?var entry = fx.deserialize(formData);cal = new Date(NaN),/ Makes a date object for the new eventevent = new Date(NaN),/ Extracts the calendar month from the H2 IDcdata = $(“h2“).attr(“id“).split(-),/ Extracts the event day, month, and yeardate = entry.event_start.split( )0,/ Splits the
27、event data into piecesedata = date.split(-);/ Sets the date for the calendar date objectcal.setFullYear(cdata1, cdata2, 1);/ Sets the date for the event date objectevent.setFullYear(edata0, edata1, edata2);event.setMinutes(1);if ( cal.getFullYear()=event.getFullYear() / Adds a leading zero to 1-digi
28、t daysday = day.length=1 ? “0“+day : day;$(“).hide().attr(“href“, “view.php?event_id=“+data).text(entry.event_title).insertAfter($(“strong:contains(“+day+“)“).delay(1000).fadeIn(“slow“);,“deserialize“ : function(str)var data = str.split(“/ Loops through each name-value pairfor ( x in data )/ Splits
29、each pair into an arraypairs = datax.split(“=“);/ The first element is the namekey = pairs0;/ Second element is the valueval = pairs1;/ Stores each value as an object propertyentrykey = fx.urldecode(val);return entry;,“urldecode“ : function(str) / Converts plus signs to spacesvar converted = str.rep
30、lace(/+/g, );/ Converts any encoded entities backreturn decodeURIComponent(converted);$(“lia“).live(“click“, function(event)event.preventDefault();$(this).addClass(“active“);var data = $(this).attr(“href“).replace(/.+?(.*)$/, “$1“),modal = fx.initModal();$(“).attr(“href“, “#“).addClass(“modal-close-
31、btn“).html(“).click(function(event)/ Prevent the default actionfx.boxout(event);).appendTo(modal);$.ajax(type: “POST“,url: processFile,data: “action=event_view,error: function(msg) modal.append(msg);););$(“.admin-options form,.admin“).live(“click“, function(event)/ Prevents the form from submittinge
32、vent.preventDefault();/ Loads the action for the processing filevar action = $(event.target).attr(“name“) | “edit_event“;id = $(event.target).siblings(“inputname=event_id“).val();id = ( id!=undefined ) ? “/ Loads the editing form and displays it$.ajax(type: “POST“,url: processFile,data: “action=“+ac
33、tion+id,success: function(data)/ Hides the formvar form = $(data).hide(),/ Make sure the modal window existsmodal = fx.initModal().children(“:not(.modal-close-btn)“).remove().end();fx.boxin(null, modal);form.appendTo(modal).addClass(“edit-form“).fadeIn(“slow“);,error: function(msg)alert(msg);););$(“
34、.edit-form inputtype=submit“).live(“click“, function(event)/ Prevents the default form action from executingevent.preventDefault();/ Serializes the form data for use with $.ajax()var formData = $(this).parents(“form“).serialize(),/ Stores the value of the submit buttonsubmitVal = $(this).val(),remov
35、e = false;start = $(this).siblings(“name=event_start“).val(),end = $(this).siblings(“name=event_start“).val();/ If this is the deletion form, appends an actionif ( $(this).attr(“name“)=“confirm_delete“ )/ Adds necessary info to the query stringformData += “if ( submitVal=“?“ )remove = true;if ( $(th
36、is).siblings(“name=action“).val()=“event_edit“ )if ( !validDate(start) | !validDate(end) )alert(“Valid dates only! (YYYY-MM-DD HH:MM:SS)“);return false;$.ajax(type: “POST“,url: processFile,data: formData,success: function(data) if ( remove=true )fx.removeevent();/ Fades out the modal windowfx.boxout
37、();fx.addevent(data, formData);,error: function(msg)alert(msg);););$(“.edit-form a:contains(cancel)“).live(“click“, function(event)fx.boxout(event);););还有是 jquery 文件大家自己到网上下载就行;下面是 valid-date.js 文件:function validDate(date)/ Define the regex pattern to validate the formatvar pattern = /(d4(-d2)2 (d2)
38、(:d2)2)$/;/ Returns true if the date matches, false if it doesntreturn date.match(pattern)!=null;app 里的文件到这里就结束了,下面是系统目录文件:class 目录:admin 类:_saltLength = $saltLength;public function processLoginForm()if ( $_POSTaction!=user_login )return “Invalid action supplied for processLoginForm.“;$uname = htmle
39、ntities($_POSTuname, ENT_QUOTES,“UTF-8“);$pword = htmlentities($_POSTpword, ENT_QUOTES,“UTF-8“);$sql = “SELECT user_id, user_name, user_email, user_pass FROM users WHERE user_name = :uname LIMIT 1“;try$stmt = $this-db-prepare($sql);$stmt-bindParam(:uname, $uname, PDO:PARAM_STR);$stmt-execute();$user
40、 = array_shift($stmt-fetchAll();$stmt-closeCursor();catch ( Exception $e )die ( $e-getMessage() );if ( !isset($user) )return “No user found with that ID.“;$hash = $this-_getSaltedHash($pword, $useruser_pass);if ( $useruser_pass=$hash )$_SESSIONuser = array(id = $useruser_id,name = $useruser_name,ema
41、il = $useruser_email);return TRUE;elsereturn “Your username or password is invalid.“;public function testSaltedHash($string, $salt=NULL)return $this-_getSaltedHash($string, $salt);public function processLogout()if ( $_POSTaction!=user_logout )return “Invalid action supplied for processLogout.“;sessi
42、on_destroy();return TRUE;private function _getSaltedHash($string, $salt=NULL)if ($salt=NULL)$salt = substr(md5(time(), 0, $this-_saltLength);else$salt = substr($salt, 0, $this-_saltLength);return $salt.sha1($salt . $string);?Calendar 类:_useDate = $useDate;else$this-_useDate = date(Y-m-d H:i:s);$ts =
43、 strtotime($this-_useDate);$this-_m = date(m, $ts);$this-_y = date(Y, $ts);$this-_daysInMonth = cal_days_in_month(CAL_GREGORIAN,$this-_m,$this-_y);$ts = mktime(0, 0, 0, $this-_m, 1, $this-_y);$this-_startDay = date(w, $ts);public function buildCalendar()$cal_month = date(F Y, strtotime($this-_useDat
44、e);$cal_id = date(Y-m, strtotime($this-_useDate);$weekdays = array(Sun, Mon, Tue,Wed, Thu, Fri, Sat);$html = “nt$cal_month“;for ( $d=0, $labels=NULL; $d“ . $weekdays$d . “;$html .= “nt“. $labels . “nt“;/* Load events data*/$events = $this-_createEventObj();/* Create the calendar markup*/$html .= “nt
45、“; / Start a new unordered listfor ( $i=1, $c=1, $t=date(j), $m=date(m), $y=date(Y);$c_daysInMonth; +$i )$event_info = NULL; / clear the variable/为该月的之前几天添加填充项$class = $i_startDay ? “fill“ : NULL;/如果当前处理日期是今天,则为他添加 class todayif ( $c=$t $ls = sprintf(“ntt“, $class);$le = “ntt“;if ( $this-_startDay_d
46、aysInMonth=$c)if ( isset($events$c) )foreach ( $events$c as $event )$link = id .“.$event-title. ;$event_info = “nttt$link“;$date = sprintf(“nttt%02d“,$c+);else$date=“;/如果赶上星期六,就新起一行$wrap = $i!=0 /Assemble the pieces into a finished item$html .= $ls . $date . $event_info . $le . $wrap;/Add filler to
47、finish out the last weekwhile ( $i%7!=1 )$html .= “ntt“;+$i;/Close the final unordered list$html .= “ntnn“;$admin = $this-_adminGeneralOptions();return $html.$admin;public function displayEvent($id)/* Make sure an ID was passed* */if ( empty($id) )return NULL;/* Make sure the ID is an integer*/$id = preg_replace(/0-9/, , $id);/* Load the event data from the DB*/$event = $this-_loadEventById($id);/* Generate strings for the date, start, and end time* */$ts = strtotime($