ab083b05bcd0eedd26a1305073b1b4638f47bb5c
[atutor.git] / docs / mods / _standard / patcher / include / common.inc.php
1 <?php\r
2 /************************************************************************/\r
3 /* ATutor                                                               */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2002-2010                                              */\r
6 /* Inclusive Design Institute                                           */\r
7 /* http://atutor.ca                                                     */\r
8 /*                                                                      */\r
9 /* This program is free software. You can redistribute it and/or        */\r
10 /* modify it under the terms of the GNU General Public License          */\r
11 /* as published by the Free Software Foundation.                        */\r
12 /************************************************************************/\r
13 \r
14 function print_errors( $errors, $notes='' ) {\r
15         ?>\r
16         <div class="input-form">\r
17         <table border="0" class="errbox" cellpadding="3" cellspacing="2" width="100%" summary="" align="center">\r
18         <tr class="errbox">\r
19                 <td>\r
20                 <h3 class="err"><img src="images/bad.gif" align="top" alt="" class="img" /> Warning</h3>\r
21                 <?php\r
22                         echo '<ul>';\r
23                         foreach ($errors as $p) {\r
24                                 echo '<li>'.$p.'</li>';\r
25                         }\r
26                         echo '</ul>';\r
27                 ?>\r
28                 </td>\r
29         </tr>\r
30         <tr>\r
31                 <td>\r
32                 <?php echo $notes; ?>\r
33                 </td>\r
34         </tr>\r
35         </table>\r
36         </div>\r
37 <?php\r
38 }\r
39 \r
40 function print_feedback( $feedback, $notes='' ) {\r
41         ?>\r
42         <div class="input-form">\r
43         <table border="0" class="fbkbox" cellpadding="3" cellspacing="2" width="100%" summary="" align="center">\r
44         <tr class="fbkbox">\r
45         <td><h3 class="feedback2"><img src="images/feedback.gif" align="top" alt="" class="img" /> The patch has been installed successfully!</h3>\r
46                 <?php\r
47                         echo '<ul>';\r
48                         foreach ($feedback as $p) {\r
49                                 echo '<li>'.$p.'</li>';\r
50                         }\r
51                         echo '</ul>';\r
52                 ?></td>\r
53         </tr>\r
54         <tr>\r
55                 <td>\r
56                 <?php echo $notes; ?>\r
57                 </td>\r
58         </tr>\r
59         </table>\r
60         </div>\r
61 <?php\r
62 }\r
63 \r
64 \r
65 /**\r
66 * update patches.remove_permission_files & patches.backup_files\r
67 * @access  private\r
68 * @author  Cindy Qi Li\r
69 */\r
70 function updatePatchesRecord($patch_id, $updateInfo)\r
71 {\r
72         global $db;\r
73         \r
74         $sql_prefix = "Update ". TABLE_PREFIX. "patches set ";\r
75         \r
76         foreach ($updateInfo as $key => $value)\r
77         {\r
78                 $sql_middle .= $key . "='" . $value . "', ";\r
79         }\r
80         \r
81         $sql = substr($sql_prefix . $sql_middle, 0, -2) . " where patches_id = " . $patch_id;\r
82 \r
83         $result = mysql_query($sql, $db) or die(mysql_error());\r
84         \r
85         return true;\r
86 }\r
87 \r
88 /**\r
89 * This function deletes $dir recrusively without deleting $dir itself.\r
90 * @access  public\r
91 * @param   string $charsets_array       The name of the directory where all files and folders under needs to be deleted\r
92 * @author  Cindy Qi Li\r
93 */\r
94 function clear_dir($dir) {\r
95         require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');\r
96                 \r
97         if(!$opendir = @opendir($dir)) {\r
98                 return false;\r
99         }\r
100         \r
101         while(($readdir=readdir($opendir)) !== false) {\r
102                 if (($readdir !== '..') && ($readdir !== '.')) {\r
103                         $readdir = trim($readdir);\r
104 \r
105                         clearstatcache(); /* especially needed for Windows machines: */\r
106 \r
107                         if (is_file($dir.'/'.$readdir)) {\r
108                                 if(!@unlink($dir.'/'.$readdir)) {\r
109                                         return false;\r
110                                 }\r
111                         } else if (is_dir($dir.'/'.$readdir)) {\r
112                                 /* calls lib function to clear subdirectories recrusively */\r
113                                 if(!clr_dir($dir.'/'.$readdir)) {\r
114                                         return false;\r
115                                 }\r
116                         }\r
117                 }\r
118         } /* end while */\r
119 \r
120         @closedir($opendir);\r
121         \r
122         return true;\r
123 }\r
124 \r
125 /**\r
126  * Check if the patch has been installed\r
127  */\r
128 function is_patch_installed($patch_id)\r
129 {\r
130         global $db;\r
131         \r
132         // Only displays the patches that are not installed\r
133         $sql = "select count(*) num_of_installed from ".TABLE_PREFIX."patches " .\r
134                "where atutor_patch_id = '" . $patch_id ."'".\r
135                " and applied_version = '".VERSION."'".\r
136                " and status like '%Installed'";\r
137 \r
138         $result = mysql_query($sql, $db) or die(mysql_error());\r
139         $row = mysql_fetch_assoc($result);\r
140         \r
141         if ($row["num_of_installed"] > 0) return true;\r
142         else return false;\r
143 }\r
144 \r
145 ?>\r