2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2002-2010 */
\r
6 /* Inclusive Design Institute */
\r
7 /* http://atutor.ca */
\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
15 define('AT_INCLUDE_PATH', '../../../include/');
\r
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
\r
17 admin_authenticate(AT_ADMIN_PRIV_PATCHER);
\r
18 require_once('classes/PatchListParser.class.php');
\r
19 require_once('include/common.inc.php');
\r
24 * Generate html of each patch row at main patch page
\r
26 function print_patch_row($patch_row, $row_id, $enable_radiotton)
\r
28 global $id, $patch_id; // current selected patch
\r
29 global $dependent_patches;
\r
31 if ($dependent_patches =="")
\r
32 $description = $patch_row["description"];
\r
34 $description = $patch_row["description"] . _AT('patch_dependent_patch_not_installed') . "<span style='color: red'>" . $dependent_patches . "</span>";
\r
36 <tr <?php if ($enable_radiotton) echo 'onmousedown="document.form[\'m'. $row_id.'\'].checked = true; rowselect(this);" id="r_'. $row_id .'"'; ?>>
\r
37 <td><input type="radio" name="id" value="<?php echo $row_id; ?>"<?php if ($enable_radiotton) echo 'id="m'. $row_id.'"'; ?> <?php if (!$enable_radiotton) echo 'disabled="disabled" '; if (strcmp($row_id, $id) == 0 || strcmp($row_id, $patch_id) == 0) echo "checked "?> /></td>
\r
38 <td><label <?php if ($enable_radiotton) echo 'for="m'.$row_id.'"'; ?>><?php echo $patch_row["atutor_patch_id"]; ?></label></td>
\r
39 <td><?php echo $description; ?></td>
\r
40 <td><?php if (!isset($patch_row['status'])) echo _AT("not_installed"); else echo $patch_row["status"]; ?></td>
\r
41 <td><?php echo $patch_row["available_to"]; ?></td>
\r
42 <td><?php echo $patch_row["author"]; ?></td>
\r
43 <td><?php if (isset($patch_row['status'])) echo ($patch_row["installed_date"]=='0000-00-00 00:00:00')?_AT('na'):$patch_row["installed_date"]; ?></td>
\r
46 if (preg_match('/Installed/', $patch_row["status"]) > 0 && ($patch_row["remove_permission_files"]<> "" || $patch_row["backup_files"]<>"" || $patch_row["patch_files"]<> ""))
\r
48 <div class="row buttons">
\r
49 <input type="button" align="middle" name="info" value="'._AT('view_message').'" onclick="location.href=\''. $_SERVER['PHP_SELF'] .'?patch_id='.$row_id.'\'" />
\r
57 // split a string by given delimiter and return an array
\r
58 function get_array_by_delimiter($subject, $delimiter)
\r
60 return preg_split('/'.preg_quote($delimiter).'/', $subject, -1, PREG_SPLIT_NO_EMPTY);
\r
63 $skipFilesModified = false;
\r
65 if ($_POST['yes']) $skipFilesModified = true;
\r
69 unset($_SESSION['remove_permission']);
\r
70 $msg->addFeedback('CANCELLED');
\r
71 header('Location: index_admin.php');
\r
75 require (AT_INCLUDE_PATH.'header.inc.php');
\r
77 if (trim($_POST['who']) != '') $who = trim($_POST['who']);
\r
78 elseif (trim($_REQUEST['who']) != '') $who = trim($_REQUEST['who']);
\r
79 else $who = "public";
\r
81 // check the connection to server update.atutor.ca
\r
82 $update_server = "http://update.atutor.ca";
\r
83 $connection_test_file = $update_server . '/index.php';
\r
84 $connection = @file_get_contents($connection_test_file);
\r
88 $infos = array('CANNOT_CONNECT_PATCH_SERVER', $update_server);
\r
89 $msg->addInfo($infos);
\r
90 $server_connected = false;
\r
93 $server_connected = true;
\r
95 // get patch list if successfully connect to patch server
\r
96 if ($server_connected)
\r
98 $patch_folder = $update_server . '/patch/' . str_replace('.', '_', VERSION) . '/';
\r
100 $patch_list_xml = @file_get_contents($patch_folder . 'patch_list.xml');
\r
102 if ($patch_list_xml)
\r
104 $patchListParser = new PatchListParser();
\r
105 $patchListParser->parse($patch_list_xml);
\r
106 $patch_list_array = $patchListParser->getMyParsedArrayForVersion(VERSION);
\r
109 // end of get patch list
\r
111 $module_content_folder = AT_CONTENT_DIR . "patcher";
\r
113 if ($_POST['install_upload'] && $_POST['uploading'])
\r
115 include_once(AT_INCLUDE_PATH . '/classes/pclzip.lib.php');
\r
117 // clean up module content folder
\r
118 clear_dir($module_content_folder);
\r
120 // 1. unzip uploaded file to module's content directory
\r
121 $archive = new PclZip($_FILES['patchfile']['tmp_name']);
\r
123 if ($archive->extract(PCLZIP_OPT_PATH, $module_content_folder) == 0)
\r
125 clear_dir($module_content_folder);
\r
126 $msg->addError('CANNOT_UNZIP');
\r
130 // Installation process
\r
131 if ($_POST['install'] || $_POST['install_upload'] && !isset($_POST["not_ignore_version"]))
\r
134 if (isset($_POST['id'])) $id=$_POST['id'];
\r
135 else $id = $_REQUEST['id'];
\r
137 if ($_POST['install'] && $id == "")
\r
139 $msg->addError('CHOOSE_UNINSTALLED_PATCH');
\r
143 if ($_POST['install'])
\r
145 $patchURL = $patch_folder . $patch_list_array[$id][patch_folder] . "/";
\r
147 else if ($_POST['install_upload'])
\r
149 $patchURL = $module_content_folder . "/";
\r
152 $patch_xml = @file_get_contents($patchURL . 'patch.xml');
\r
154 if ($patch_xml === FALSE)
\r
156 $msg->addError('PATCH_XML_NOT_FOUND');
\r
160 require_once('classes/PatchParser.class.php');
\r
161 require_once('classes/Patch.class.php');
\r
163 $patchParser = new PatchParser();
\r
164 $patchParser->parse($patch_xml);
\r
166 $patch_array = $patchParser->getParsedArray();
\r
168 if ($_POST["ignore_version"]) $patch_array["applied_version"] = VERSION;
\r
170 if ($_POST["install_upload"])
\r
172 $current_patch_list = array('atutor_patch_id' => $patch_array['atutor_patch_id'],
\r
173 'applied_version' => $patch_array['applied_version'],
\r
174 'patch_folder' => $patchURL,
\r
175 'available_to' => 'private',
\r
176 'author' => $patch_array['author'],
\r
177 'sql' => $patch_array['sql'],
\r
178 'description' => $patch_array['description'],
\r
179 'dependent_patches' => $patch_array['dependent_patches']);
\r
182 if ($_POST["install"])
\r
184 $current_patch_list = $patch_list_array[$id];
\r
185 $current_patch_list["sql"] = $patch_array["sql"];
\r
188 if ($_POST["install_upload"] && is_patch_installed($patch_array["atutor_patch_id"]))
\r
189 $msg->addError('PATCH_ALREADY_INSTALLED');
\r
192 $patch = new Patch($patch_array, $current_patch_list, $skipFilesModified, $patchURL);
\r
194 if ($patch->applyPatch()) $patch_id = $patch->getPatchID();
\r
199 // end of patch installation
\r
201 // display permission and backup files message
\r
202 if (isSet($_REQUEST['patch_id'])) $patch_id = $_REQUEST['patch_id'];
\r
203 elseif ($_POST['patch_id']) $patch_id=$_POST['patch_id'];
\r
207 // clicking on button "Done" at displaying remove permission info page
\r
208 if ($_POST['done'])
\r
210 $permission_files = array();
\r
212 if (is_array($_SESSION['remove_permission']))
\r
214 foreach ($_SESSION['remove_permission'] as $file)
\r
216 if (is_writable($file)) $permission_files[] = $file;
\r
220 if (count($permission_files) == 0)
\r
222 $updateInfo = array("remove_permission_files"=>"", "status"=>"Installed");
\r
224 updatePatchesRecord($patch_id, $updateInfo);
\r
228 foreach($permission_files as $permission_file)
\r
229 $remove_permission_files .= $permission_file. '|';
\r
231 $updateInfo = array("remove_permission_files"=>preg_quote($remove_permission_files), "status"=>"Partly Installed");
\r
233 updatePatchesRecord($patch_id, $updateInfo);
\r
238 // display remove permission info
\r
239 unset($_SESSION['remove_permission']);
\r
241 $sql = "SELECT * FROM ".TABLE_PREFIX."patches
\r
242 WHERE patches_id = " . $patch_id;
\r
244 $result = mysql_query($sql, $db) or die(mysql_error());
\r
245 $row = mysql_fetch_assoc($result);
\r
247 if ($row["remove_permission_files"]<> "")
\r
249 $remove_permission_files = $_SESSION['remove_permission'] = get_array_by_delimiter($row["remove_permission_files"], "|");
\r
251 if (count($_SESSION['remove_permission']) > 0)
\r
253 if ($_POST['done']) $msg->printErrors('REMOVE_WRITE_PERMISSION');
\r
254 else $msg->printInfos('PATCH_INSTALLED_AND_REMOVE_PERMISSION');
\r
256 $feedbacks[] = _AT('remove_write_permission');
\r
258 foreach($remove_permission_files as $remove_permission_file)
\r
259 if ($remove_permission_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $remove_permission_file . "</strong><br />";
\r
261 $notes = '<form action="'. $_SERVER['PHP_SELF'].'?patch_id='.$patch_id.'" method="post" name="remove_permission">
\r
262 <div class="row buttons">
\r
263 <input type="hidden" name="patch_id" value="'.$patch_id.'" />
\r
264 <input type="submit" name="done" value="'._AT('done').'" accesskey="d" />
\r
269 print_errors($feedbacks, $notes);
\r
272 // display backup file info after remove permission step
\r
273 if ($row["remove_permission_files"] == "")
\r
275 $msg->printFeedbacks('PATCH_INSTALLED_SUCCESSFULLY');
\r
277 if ($row["backup_files"]<> "")
\r
279 $backup_files = get_array_by_delimiter($row["backup_files"], "|");
\r
281 if (count($backup_files) > 0)
\r
283 $feedbacks[] = _AT('patcher_show_backup_files');
\r
285 foreach($backup_files as $backup_file)
\r
286 if ($backup_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $backup_file . "</strong><br />";
\r
290 if ($row["patch_files"]<> "")
\r
292 $patch_files = get_array_by_delimiter($row["patch_files"], "|");
\r
294 if (count($patch_files) > 0)
\r
296 $feedbacks[] = _AT('patcher_show_patch_files');
\r
298 foreach($patch_files as $patch_file)
\r
299 if ($patch_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $patch_file . "</strong><br />";
\r
304 if (count($feedbacks)> 0)
\r
305 print_feedback($feedbacks);
\r
307 print_feedback(array());
\r
314 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
315 <div class="input-form">
\r
317 <table class="data" summary="" style="width: 100%" rules="cols">
\r
320 <th scope="col"> </th>
\r
321 <th scope="col"><?php echo _AT('atutor_patch_id');?></th>
\r
322 <th scope="col"><?php echo _AT('description');?></th>
\r
323 <th scope="col"><?php echo _AT('status');?></th>
\r
324 <th scope="col"><?php echo _AT('available_to');?></th>
\r
325 <th scope="col"><?php echo _AT('author');?></th>
\r
326 <th scope="col"><?php echo _AT('installed_date');?></th>
\r
327 <th scope="col"><?php echo _AT('view_message');?></th>
\r
333 // display installed patches
\r
334 $sql = "select * from ".TABLE_PREFIX."patches " .
\r
335 "where applied_version = '" . VERSION . "' ".
\r
336 "order by atutor_patch_id";
\r
338 $result = mysql_query($sql, $db);
\r
339 $num_of_patches = mysql_num_rows($result) + count($patch_list_array);
\r
341 if ($num_of_patches == 0)
\r
348 echo _AT('none_found');
\r
357 while ($row = mysql_fetch_assoc($result))
\r
359 print_patch_row($row, $row['patches_id'], false);
\r
363 // display un-installed patches
\r
364 if(is_array($patch_list_array))
\r
366 foreach ($patch_list_array as $row_num => $new_patch)
\r
368 if (!is_patch_installed($new_patch['atutor_patch_id']))
\r
370 $dependent_patches_installed = true;
\r
371 $dependent_patches = "";
\r
373 // check if the dependent patches are installed
\r
374 if (is_array($new_patch["dependent_patches"]))
\r
377 foreach ($new_patch["dependent_patches"] as $num => $dependent_patch)
\r
379 if (!is_patch_installed($dependent_patch))
\r
381 $dependent_patches_installed = false;
\r
382 $dependent_patches .= $dependent_patch. ", ";
\r
386 // remove the last comma in the string
\r
387 if ($dependent_patches <> "") $dependent_patches = substr($dependent_patches, 0, -2);
\r
390 // display patch row
\r
391 if ($dependent_patches_installed)
\r
392 print_patch_row($new_patch, $array_id++, true);
\r
395 print_patch_row($new_patch, $array_id++, false);
\r
396 $dependent_patches_installed = true;
\r
408 <input type="submit" name="install" value="<?php echo _AT('install'); ?>" />
\r
421 <form name="frm_upload" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
\r
423 <div class="input-form">
\r
424 <div class="row"><?php echo _AT("upload_patch"); ?></div>
\r
427 <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
\r
428 <input type="file" name="patchfile" size="50" />
\r
431 <div class="row buttons">
\r
432 <input type="submit" name="install_upload" value="Install" onclick="javascript: return validate_filename(); " class="submit" />
\r
433 <input type="hidden" name="uploading" value="1" />
\r
439 <script language="JavaScript">
\r
442 String.prototype.trim = function() {
\r
443 return this.replace(/^\s+|\s+$/g,"");
\r
446 // This function validates if and only if a zip file is given
\r
447 function validate_filename() {
\r
449 var file = document.frm_upload.patchfile.value;
\r
450 if (!file || file.trim()=='') {
\r
451 alert('Please give a zip file!');
\r
455 if(file.slice(file.lastIndexOf(".")).toLowerCase() != '.zip') {
\r
456 alert('Please upload ZIP file only!');
\r
465 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\r