2 define('AT_INCLUDE_PATH', '../../include/');
\r
3 require (AT_INCLUDE_PATH.'vitals.inc.php');
\r
4 admin_authenticate(AT_ADMIN_PRIV_PATCHER);
\r
5 require (AT_INCLUDE_PATH.'header.inc.php');
\r
7 require_once('include/common.inc.php');
\r
12 * Generate html of each patch row at main patch page
\r
14 function print_patch_row($patch_row, $row_id, $enable_radiotton)
\r
16 global $id, $patch_id; // current selected patch
\r
17 global $dependent_patches;
\r
19 if ($dependent_patches =="")
\r
20 $description = $patch_row["description"];
\r
22 $description = $patch_row["description"] . _AT('patch_dependent_patch_not_installed') . "<span style='color: red'>" . $dependent_patches . "</span>";
\r
24 <tr <?php if ($enable_radiotton) echo 'onmousedown="document.form[\'m'. $row_id.'\'].checked = true; rowselect(this);"'; ?> id="r_<?php echo $row_id; ?>">
\r
25 <td><input type="radio" name="id" value="<?php echo $row_id; ?>" id="m<?php echo $row_id; ?>" <?php if (!$enable_radiotton) echo "disabled "; if (strcmp($row_id, $id) == 0 || strcmp($row_id, $patch_id) == 0) echo "checked "?> /></td>
\r
26 <td><label for="m<?php echo $row_id; ?>"><?php echo $patch_row["atutor_patch_id"]; ?></label></td>
\r
27 <td><?php echo $description; ?></td>
\r
28 <td><?php if (!isset($patch_row['status'])) echo "Uninstalled"; else echo $patch_row["status"]; ?></td>
\r
29 <td><?php echo $patch_row["available_to"]; ?></td>
\r
32 if (preg_match('/Installed/', $patch_row["status"]) > 0 && ($patch_row["remove_permission_files"]<> "" || $patch_row["backup_files"]<>"" || $patch_row["patch_files"]<> ""))
\r
34 <div class="row buttons">
\r
35 <input type="button" align="center" name="info" value="'._AT('view_message').'" onClick="location.href=\''. $_SERVER['PHP_SELF'] .'?patch_id='.$row_id.'\'" />
\r
43 // split a string by given delimiter and return an array
\r
44 function get_array_by_delimiter($subject, $delimiter)
\r
46 return preg_split('/'.preg_quote($delimiter).'/', $subject, -1, PREG_SPLIT_NO_EMPTY);
\r
49 $skipFilesModified = false;
\r
51 if ($_POST['yes']) $skipFilesModified = true;
\r
53 require_once('classes/PatchListParser.class.php');
\r
55 if (trim($_POST['who']) != '') $who = trim($_POST['who']);
\r
56 elseif (trim($_REQUEST['who']) != '') $who = trim($_REQUEST['who']);
\r
57 else $who = "public";
\r
59 // check the connection to server update.atutor.ca
\r
60 $update_server = "update.atutor.ca";
\r
62 $file = fsockopen ($update_server, 80, $errno, $errstr, 15);
\r
66 print '<span style="color: red"><b>Error: Cannot connect to patch server: '. $update_server . '</b></span>';
\r
71 $patch_folder = "http://" . $update_server . '/patch/' . str_replace('.', '_', VERSION) . '/';
\r
73 $patch_list_xml = @file_get_contents($patch_folder . 'patch_list.xml');
\r
75 if ($patch_list_xml === FALSE)
\r
77 echo _AT('none_found');
\r
81 $patchListParser =& new PatchListParser();
\r
82 $patchListParser->parse($patch_list_xml);
\r
83 $patch_list_array = $patchListParser->getMyParsedArrayForVersion(VERSION);
\r
85 // end of get patch list
\r
87 $module_content_folder = AT_CONTENT_DIR . "patcher";
\r
89 if ($_POST['install_upload'] && $_POST['uploading'])
\r
91 include_once(AT_INCLUDE_PATH . '/classes/pclzip.lib.php');
\r
93 // clean up module content folder
\r
94 clear_dir($module_content_folder);
\r
96 // 1. unzip uploaded file to module's content directory
\r
97 $archive = new PclZip($_FILES['patchfile']['tmp_name']);
\r
99 if ($archive->extract(PCLZIP_OPT_PATH, $module_content_folder) == 0)
\r
101 clear_dir($module_content_folder);
\r
102 $msg->addError('CANNOT_UNZIP');
\r
106 // Installation process
\r
107 if ($_POST['install'] || $_POST['install_upload'])
\r
110 if (isset($_POST['id'])) $id=$_POST['id'];
\r
111 else $id = $_REQUEST['id'];
\r
113 if ($_POST['install'] && $id == "")
\r
115 $msg->addError('CHOOSE_UNINSTALLED_PATCH');
\r
119 if ($_POST['install'])
\r
121 $patchURL = $patch_folder . $patch_list_array[$id][patch_folder] . "/";
\r
123 else if ($_POST['install_upload'])
\r
125 $patchURL = $module_content_folder . "/";
\r
128 $patch_xml = @file_get_contents($patchURL . 'patch.xml');
\r
130 if ($patch_xml === FALSE)
\r
132 $msg->addError('PATCH_XML_NOT_FOUND');
\r
136 require_once('classes/PatchParser.class.php');
\r
137 require_once('classes/Patch.class.php');
\r
139 $patchParser =& new PatchParser();
\r
140 $patchParser->parse($patch_xml);
\r
142 $patch_array = $patchParser->getParsedArray();
\r
144 if ($_POST["install_upload"])
\r
146 $current_patch_list = array('atutor_patch_id' => $patch_array['atutor_patch_id'],
\r
147 'applied_version' => $patch_array['applied_version'],
\r
148 'patch_folder' => $patchURL,
\r
149 'available_to' => 'private',
\r
150 'description' => $patch_array['description'],
\r
151 'dependent_patches' => $patch_array['dependent_patches']);
\r
154 if ($_POST["install"])
\r
156 $current_patch_list = $patch_list_array[$id];
\r
159 if ($_POST["install_upload"] && is_patch_installed($patch_array["atutor_patch_id"]))
\r
160 $msg->addError('PATCH_ALREADY_INSTALLED');
\r
163 $patch = & new Patch($patch_array, $current_patch_list, $skipFilesModified, $patchURL);
\r
165 if ($patch->applyPatch()) $patch_id = $patch->getPatchID();
\r
170 // end of patch installation
\r
172 // display permission and backup files message
\r
173 if (isSet($_REQUEST['patch_id'])) $patch_id = $_REQUEST['patch_id'];
\r
174 elseif ($_POST['patch_id']) $patch_id=$_POST['patch_id'];
\r
178 // clicking on button "Done" at displaying remove permission info page
\r
179 if ($_POST['done'])
\r
181 $permission_files = array();
\r
183 if (is_array($_SESSION['remove_permission']))
\r
185 foreach ($_SESSION['remove_permission'] as $file)
\r
187 if (is_writable($file)) $permission_files[] = $file;
\r
191 if (count($permission_files) == 0)
\r
193 $updateInfo = array("remove_permission_files"=>"", "status"=>"Installed");
\r
195 updatePatchesRecord($patch_id, $updateInfo);
\r
199 foreach($permission_files as $permission_file)
\r
200 $remove_permission_files .= $permission_file. '|';
\r
202 $updateInfo = array("remove_permission_files"=>preg_quote($remove_permission_files), "status"=>"Partly Installed");
\r
204 updatePatchesRecord($patch_id, $updateInfo);
\r
209 // display remove permission info
\r
210 unset($_SESSION['remove_permission']);
\r
212 $sql = "SELECT * FROM ".TABLE_PREFIX."patches
\r
213 WHERE patches_id = " . $patch_id;
\r
215 $result = mysql_query($sql, $db) or die(mysql_error());
\r
216 $row = mysql_fetch_assoc($result);
\r
218 if ($row["remove_permission_files"]<> "")
\r
220 $remove_permission_files = $_SESSION['remove_permission'] = get_array_by_delimiter($row["remove_permission_files"], "|");
\r
222 if (count($_SESSION['remove_permission']) > 0)
\r
224 if ($_POST['done']) $msg->printErrors('REMOVE_WRITE_PERMISSION');
\r
225 else $msg->printInfos('PATCH_INSTALLED_AND_REMOVE_PERMISSION');
\r
227 $feedbacks[] = _AT('remove_write_permission');
\r
229 foreach($remove_permission_files as $remove_permission_file)
\r
230 if ($remove_permission_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $remove_permission_file . "</strong><br>";
\r
232 $notes = '<form action="'. $_SERVER['PHP_SELF'].'?patch_id='.$patch_id.'" method="post" name="remove_permission">
\r
233 <div class="row buttons">
\r
234 <input type="hidden" name="patch_id" value="'.$patch_id.'" />
\r
235 <input type="submit" name="done" value="'._AT('done').'" accesskey="d" />
\r
240 print_errors($feedbacks, $notes);
\r
243 // display backup file info after remove permission step
\r
244 if ($row["remove_permission_files"] == "")
\r
246 $msg->printFeedbacks('PATCH_INSTALLED_SUCCESSFULLY');
\r
248 if ($row["backup_files"]<> "")
\r
250 $backup_files = get_array_by_delimiter($row["backup_files"], "|");
\r
252 if (count($backup_files) > 0)
\r
254 $feedbacks[] = _AT('patcher_show_backup_files');
\r
256 foreach($backup_files as $backup_file)
\r
257 if ($backup_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $backup_file . "</strong><br>";
\r
261 if ($row["patch_files"]<> "")
\r
263 $patch_files = get_array_by_delimiter($row["patch_files"], "|");
\r
265 if (count($patch_files) > 0)
\r
267 $feedbacks[] = _AT('patcher_show_patch_files');
\r
269 foreach($patch_files as $patch_file)
\r
270 if ($patch_file <> "") $feedbacks[count($feedbacks)-1] .= "<strong>" . $patch_file . "</strong><br>";
\r
275 if (count($feedbacks)> 0)
\r
276 print_feedback($feedbacks);
\r
278 print_feedback(array());
\r
282 $msg->printErrors();
\r
286 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
287 <div class="input-form">
\r
291 <table class="data" summary="" style="width: 100%" rules="cols">
\r
294 <th scope="col"> </th>
\r
295 <th scope="col"><?php echo _AT('atutor_patch_id');?></th>
\r
296 <th scope="col"><?php echo _AT('description');?></th>
\r
297 <th scope="col"><?php echo _AT('status');?></th>
\r
298 <th scope="col"><?php echo _AT('available_to');?></th>
\r
299 <th scope="col"><?php echo _AT('view_message');?></th>
\r
305 // display installed patches
\r
306 $sql = "select * from ".TABLE_PREFIX."patches " .
\r
307 "where applied_version = '" . VERSION . "' ".
\r
308 "order by atutor_patch_id";
\r
310 $result = mysql_query($sql, $db);
\r
311 $num_of_patches = mysql_num_rows($result) + count($patch_list_array);
\r
313 if ($num_of_patches == 0)
\r
315 echo _AT('none_found');
\r
319 while ($row = mysql_fetch_assoc($result))
\r
321 print_patch_row($row, $row['patches_id'], false);
\r
325 // display un-installed patches
\r
326 foreach ($patch_list_array as $row_num => $new_patch)
\r
328 if (!is_patch_installed($new_patch['atutor_patch_id']))
\r
330 $dependent_patches_installed = true;
\r
332 // check if the dependent patches are installed
\r
333 if (is_array($new_patch["dependent_patches"]))
\r
335 $dependent_patches = "";
\r
336 foreach ($new_patch["dependent_patches"] as $num => $dependent_patch)
\r
338 if (!is_patch_installed($dependent_patch))
\r
340 $dependent_patches_installed = false;
\r
341 $dependent_patches .= $dependent_patch. ", ";
\r
345 // remove the last comma in the string
\r
346 if ($dependent_patches <> "") $dependent_patches = substr($dependent_patches, 0, -2);
\r
349 // display patch row
\r
350 if ($dependent_patches_installed)
\r
351 print_patch_row($new_patch, $array_id++, true);
\r
354 print_patch_row($new_patch, $array_id++, false);
\r
355 $dependent_patches_installed = true;
\r
367 <input type="submit" name="install" value="<?php echo _AT('install'); ?>" />
\r
380 <FORM NAME="frm_upload" ENCTYPE="multipart/form-data" METHOD=POST ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" >
\r
382 <div class="input-form">
\r
383 <div class="row"><?php echo _AT("upload_patch"); ?></div>
\r
386 <INPUT TYPE="hidden" name="MAX_FILE_SIZE" VALUE="52428800">
\r
387 <INPUT TYPE="file" NAME="patchfile" SIZE=50>
\r
390 <div class="row buttons">
\r
391 <INPUT TYPE="submit" name="install_upload" value="Install" onClick="javascript: return validate_filename(); " class="submit" />
\r
392 <INPUT TYPE="hidden" name="uploading" value="1">
\r
398 <SCRIPT LANGUAGE="JavaScript">
\r
401 String.prototype.trim = function() {
\r
402 return this.replace(/^\s+|\s+$/g,"");
\r
405 // This function validates if and only if a zip file is given
\r
406 function validate_filename() {
\r
408 var file = document.frm_upload.patchfile.value;
\r
409 if (!file || file.trim()=='') {
\r
410 alert('Please give a zip file!');
\r
414 if(file.slice(file.lastIndexOf(".")).toLowerCase() != '.zip') {
\r
415 alert('Please upload ZIP file only!');
\r
424 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\r