2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2010 */
\r
6 /* Inclusive Design Institute */
\r
8 /* This program is free software. You can redistribute it and/or */
\r
9 /* modify it under the terms of the GNU General Public License */
\r
10 /* as published by the Free Software Foundation. */
\r
11 /************************************************************************/
\r
13 define('TR_INCLUDE_PATH', '../include/');
\r
15 require (TR_INCLUDE_PATH.'vitals.inc.php');
\r
16 require_once('classes/PatchListParser.class.php');
\r
17 require_once(TR_INCLUDE_PATH. 'classes/FileUtility.class.php');
\r
18 require_once(TR_INCLUDE_PATH. 'classes/DAO/PatchesDAO.class.php');
\r
19 require_once('include/common.inc.php');
\r
23 $patchesDAO = new PatchesDAO();
\r
26 * Generate html of each patch row at main patch page
\r
28 function print_patch_row($patch_row, $row_id, $enable_radiotton)
\r
30 global $id, $patch_id; // current selected patch
\r
31 global $dependent_patches;
\r
33 if ($dependent_patches =="")
\r
34 $description = $patch_row["description"];
\r
36 $description = $patch_row["description"] . _AT('update_dependent_update_not_installed') . "<span style='color: red'>" . $dependent_patches . "</span>";
\r
38 <tr <?php if ($enable_radiotton) echo 'onkeydown="document.form[\'m'. $row_id.'\'].checked = true; trans.utility.rowselect(this);" onmousedown="document.form[\'m'. $row_id.'\'].checked = true; trans.utility.rowselect(this);" id="r_'. $row_id .'"'; ?>>
\r
39 <td><input type="radio" name="id" value="<?php echo $row_id; ?>" id="m_<?php echo $patch_row["system_patch_id"]; ?>" <?php if (!$enable_radiotton) echo 'disabled="disabled" '; if (strcmp($row_id, $id) == 0 || strcmp($row_id, $patch_id) == 0) echo "checked "?> /></td>
\r
40 <td><label for="m_<?php echo $patch_row["system_patch_id"]; ?>"><?php echo $patch_row["system_patch_id"]; ?></label></td>
\r
41 <td><?php echo $description; ?></td>
\r
42 <td><?php if (!isset($patch_row['status'])) echo _AT("not_installed"); else echo $patch_row["status"]; ?></td>
\r
43 <td><?php echo $patch_row["available_to"]; ?></td>
\r
44 <td><?php echo $patch_row["author"]; ?></td>
\r
45 <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
48 if (preg_match('/Installed/', $patch_row["status"]) > 0 && ($patch_row["remove_permission_files"]<> "" || $patch_row["backup_files"]<>"" || $patch_row["patch_files"]<> ""))
\r
50 <div class="row buttons">
\r
51 <input type="button" align="middle" name="info" value="'._AT('view_message').'" onclick="location.href=\''. $_SERVER['PHP_SELF'] .'?patch_id='.$row_id.'\'" />
\r
59 // split a string by given delimiter and return an array
\r
60 function get_array_by_delimiter($subject, $delimiter)
\r
62 return preg_split('/'.preg_quote($delimiter).'/', $subject, -1, PREG_SPLIT_NO_EMPTY);
\r
65 $skipFilesModified = false;
\r
67 if ($_POST['yes']) $skipFilesModified = true;
\r
71 unset($_SESSION['remove_permission']);
\r
72 $msg->addFeedback('CANCELLED');
\r
73 header('Location: index.php');
\r
77 require (TR_INCLUDE_PATH.'header.inc.php');
\r
79 if (trim($_POST['who']) != '') $who = trim($_POST['who']);
\r
80 elseif (trim($_REQUEST['who']) != '') $who = trim($_REQUEST['who']);
\r
81 else $who = "public";
\r
83 // check the connection to server update.atutor.ca
\r
84 $connection_test_file = UPDATE_SERVER . '/index.php';
\r
85 $connection = @file_get_contents($connection_test_file);
\r
89 $infos = array('CANNOT_CONNECT_PATCH_SERVER', UPDATE_SERVER);
\r
90 $msg->addInfo($infos);
\r
91 $server_connected = false;
\r
94 $server_connected = true;
\r
96 // get patch list if successfully connect to patch server
\r
97 if ($server_connected)
\r
99 $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 = TR_CONTENT_DIR . "updater/temp";
\r
112 if (!is_dir($module_content_folder)) mkdir($module_content_folder);
\r
114 if ($_POST['install_upload'] && $_POST['uploading'])
\r
116 include_once(TR_INCLUDE_PATH . 'lib/pclzip.lib.php');
\r
118 // clean up module content folder
\r
119 FileUtility::clr_dir($module_content_folder);
\r
121 // 1. unzip uploaded file to module's content directory
\r
122 $archive = new PclZip($_FILES['patchfile']['tmp_name']);
\r
124 if ($archive->extract(PCLZIP_OPT_PATH, $module_content_folder) == 0)
\r
126 FileUtility::clr_dir($module_content_folder);
\r
127 $msg->addError('CANNOT_UNZIP');
\r
131 // Installation process
\r
132 if ($_POST['install'] || $_POST['install_upload'] && !isset($_POST["not_ignore_version"]))
\r
135 if (isset($_POST['id'])) $id=$_POST['id'];
\r
136 else $id = $_REQUEST['id'];
\r
138 if ($_POST['install'] && $id == "")
\r
140 $msg->addError('CHOOSE_UNINSTALLED_PATCH');
\r
144 if ($_POST['install'])
\r
146 $patchURL = $patch_folder . $patch_list_array[$id][patch_folder] . "/";
\r
148 else if ($_POST['install_upload'])
\r
150 $patchURL = $module_content_folder . "/";
\r
153 $patch_xml = @file_get_contents($patchURL . 'patch.xml');
\r
155 if ($patch_xml === FALSE)
\r
157 $msg->addError('PATCH_XML_NOT_FOUND');
\r
161 require_once('classes/PatchParser.class.php');
\r
162 require_once('classes/Patch.class.php');
\r
164 $patchParser = new PatchParser();
\r
165 $patchParser->parse($patch_xml);
\r
167 $patch_array = $patchParser->getParsedArray();
\r
169 if ($_POST["ignore_version"]) $patch_array["applied_version"] = VERSION;
\r
171 if ($_POST["install_upload"])
\r
173 $current_patch_list = array('system_patch_id' => $patch_array['system_patch_id'],
\r
174 'applied_version' => $patch_array['applied_version'],
\r
175 'patch_folder' => $patchURL,
\r
176 'available_to' => 'private',
\r
177 'author' => $patch_array['author'],
\r
178 'sql' => $patch_array['sql'],
\r
179 'description' => $patch_array['description'],
\r
180 'dependent_patches' => $patch_array['dependent_patches']);
\r
183 if ($_POST["install"])
\r
185 $current_patch_list = $patch_list_array[$id];
\r
186 $current_patch_list["sql"] = $patch_array["sql"];
\r
189 if ($_POST["install_upload"] && is_patch_installed($patch_array["system_patch_id"]))
\r
190 $msg->addError('UPDATE_ALREADY_INSTALLED');
\r
193 $patch = new Patch($patch_array, $current_patch_list, $skipFilesModified, $patchURL);
\r
195 if ($patch->applyPatch()) $patch_id = $patch->getPatchID();
\r
200 // end of patch installation
\r
202 // display permission and backup files message
\r
203 if (isSet($_REQUEST['patch_id'])) $patch_id = $_REQUEST['patch_id'];
\r
204 elseif ($_POST['patch_id']) $patch_id=$_POST['patch_id'];
\r
208 // clicking on button "Done" at displaying remove permission info page
\r
209 if ($_POST['done'])
\r
211 $permission_files = array();
\r
213 if (is_array($_SESSION['remove_permission']))
\r
215 foreach ($_SESSION['remove_permission'] as $file)
\r
217 if (is_writable($file)) $permission_files[] = $file;
\r
221 if (count($permission_files) == 0)
\r
223 $updateInfo = array("remove_permission_files"=>"", "status"=>"Installed");
\r
225 $patchesDAO->UpdateByArray($patch_id, $updateInfo);
\r
229 foreach($permission_files as $permission_file)
\r
230 $remove_permission_files .= $permission_file. '|';
\r
232 $updateInfo = array("remove_permission_files"=>preg_quote($remove_permission_files), "status"=>"Partly Installed");
\r
234 $patchesDAO->UpdateByArray($patch_id, $updateInfo);
\r
239 // display remove permission info
\r
240 unset($_SESSION['remove_permission']);
\r
242 $row = $patchesDAO->getByID($patch_id);
\r
244 if ($row["remove_permission_files"]<> "")
\r
246 $remove_permission_files = $_SESSION['remove_permission'] = get_array_by_delimiter($row["remove_permission_files"], "|");
\r
248 if (count($_SESSION['remove_permission']) > 0)
\r
250 if ($_POST['done']) $msg->printErrors('REMOVE_WRITE_PERMISSION');
\r
251 else $msg->printInfos('PATCH_INSTALLED_AND_REMOVE_PERMISSION');
\r
253 $feedbacks[] = _AT('remove_write_permission');
\r
255 foreach($remove_permission_files as $remove_permission_file)
\r
256 if ($remove_permission_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $remove_permission_file . "</strong><br />";
\r
258 $notes = '<form action="'. $_SERVER['PHP_SELF'].'?patch_id='.$patch_id.'" method="post" name="remove_permission">
\r
259 <div class="row buttons">
\r
260 <input type="hidden" name="patch_id" value="'.$patch_id.'" />
\r
261 <input type="submit" name="done" value="'._AT('done').'" accesskey="d" />
\r
266 print_errors($feedbacks, $notes);
\r
269 // display backup file info after remove permission step
\r
270 if ($row["remove_permission_files"] == "")
\r
272 $msg->printFeedbacks('PATCH_INSTALLED_SUCCESSFULLY');
\r
274 if ($row["backup_files"]<> "")
\r
276 $backup_files = get_array_by_delimiter($row["backup_files"], "|");
\r
278 if (count($backup_files) > 0)
\r
280 $feedbacks[] = _AT('updater_show_backup_files');
\r
282 foreach($backup_files as $backup_file)
\r
283 if ($backup_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $backup_file . "</strong><br />";
\r
287 if ($row["patch_files"]<> "")
\r
289 $patch_files = get_array_by_delimiter($row["patch_files"], "|");
\r
291 if (count($patch_files) > 0)
\r
293 $feedbacks[] = _AT('updater_show_patch_files');
\r
295 foreach($patch_files as $patch_file)
\r
296 if ($patch_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $patch_file . "</strong><br />";
\r
301 if (count($feedbacks)> 0)
\r
302 print_feedback($feedbacks);
\r
304 print_feedback(array());
\r
310 // display installed patches
\r
311 $rows = $patchesDAO->getPatchByVersion(VERSION);
\r
313 if (is_array($rows)) $num_of_patches_in_db = count($rows);
\r
314 else $num_of_patches_in_db = 0;
\r
316 $num_of_patches = $num_of_patches_in_db + count($patch_list_array);
\r
318 $savant->assign('num_of_patches', $num_of_patches);
\r
319 $savant->assign('patches_in_db', $rows);
\r
320 $savant->assign('patch_list_array', $patch_list_array);
\r
321 $savant->assign('patches_in_db', $rows);
\r
322 $savant->assign('patches_in_db', $rows);
\r
324 $savant->display('updater/index.tmpl.php');
\r