Move a file to a new location
Work even if dest file already exists
static public renameForce ( $srce, $dest ) : boolean | ||
$srce | source file path | |
$dest | destination file path | |
return | boolean | : success |
------------------------------------------------------------------------ @package Plugin Monitoring for GLPI @author David Durieux @co-author @comment @copyright Copyright (c) 2011-2012 Plugin Monitoring for GLPI team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link https://forge.indepnet.net/projects/monitoring/ @since 2011 ------------------------------------------------------------------------ */ if (!defined('GLPI_ROOT')) { define('GLPI_ROOT', '../../..'); } include GLPI_ROOT . "/inc/includes.php"; PluginMonitoringProfile::checkRight("config", "w"); commonHeader($LANG['plugin_monitoring']['title'][0], $_SERVER["PHP_SELF"], "plugins", "monitoring", "rrdtemplates"); if (isset($_FILES['filename'])) { if (strstr($_FILES['filename']['name'], ".json")) { if (Document::renameForce($_FILES['filename']['tmp_name'], GLPI_PLUGIN_DOC_DIR . "/monitoring/templates/" . $_FILES['filename']['name'])) { addMessageAfterRedirect($LANG['document'][26]); } } glpi_header($_SERVER['HTTP_REFERER']); } $pmRrdtool = new PluginMonitoringRrdtool(); $pmRrdtool->addTemplate(); commonFooter();
function prepareInputForUpdate($input) { global $CFG_GLPI; //picture manually uploaded by user if (isset($input["_blank_picture"]) && $input["_blank_picture"]) { self::dropPictureFiles($this->fields['picture']); $input['picture'] = 'NULL'; } else { if (isset($_FILES['picture'])) { if (!count($_FILES['picture']) || empty($_FILES['picture']['name']) || !is_file($_FILES['picture']['tmp_name'])) { switch ($_FILES['picture']['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: Session::addMessageAfterRedirect(__('File too large to be added.'), false, ERROR); break; case UPLOAD_ERR_NO_FILE: // Session::addMessageAfterRedirect(__('No file specified.'),false,ERROR); break; } } else { if (toolbox::getMime($_FILES['picture']['tmp_name'], 'image')) { // Unlink old picture (clean on changing format) self::dropPictureFiles($this->fields['picture']); // Move uploaded file $filename = uniqid($this->fields['id'] . '_'); $sub = substr($filename, -2); /* 2 hex digit */ $tmp = explode(".", $_FILES['picture']['name']); $extension = array_pop($tmp); @mkdir(GLPI_PICTURE_DIR . "/{$sub}"); $picture_path = GLPI_PICTURE_DIR . "/{$sub}/{$filename}.{$extension}"; self::dropPictureFiles($filename . "." . $extension); if (in_array($extension, array('jpg', 'jpeg', 'png', 'bmp', 'gif')) && Document::renameForce($_FILES['picture']['tmp_name'], $picture_path)) { Session::addMessageAfterRedirect(__('The file is valid. Upload is successful.')); // For display $input['picture'] = "{$sub}/{$filename}.{$extension}"; //prepare a thumbnail $thumb_path = GLPI_PICTURE_DIR . "/{$sub}/{$filename}_min.{$extension}"; Toolbox::resizePicture($picture_path, $thumb_path); } else { Session::addMessageAfterRedirect(__('Potential upload attack or file too large. Moving temporary file failed.'), false, ERROR); } } else { Session::addMessageAfterRedirect(__('The file is not an image file.'), false, ERROR); } } } else { //ldap jpegphoto synchronisation. if (isset($this->fields["authtype"]) && ($this->fields["authtype"] == Auth::LDAP || Auth::isAlternateAuth($this->fields['authtype'])) && ($picture = $this->syncLdapPhoto())) { if (!empty($picture)) { $input['picture'] = $picture; } } } } if (isset($input["password2"])) { // Empty : do not update if (empty($input["password"])) { unset($input["password"]); } else { if ($input["password"] == $input["password2"]) { // Check right : my password of user with lesser rights if (isset($input['id']) && Config::validatePassword($input["password"]) && ($input['id'] == Session::getLoginUserID() || $this->currentUserHaveMoreRightThan($input['id']) || $input['password_forget_token'] == $this->fields['password_forget_token'] && abs(strtotime($_SESSION["glpi_currenttime"]) - strtotime($this->fields['password_forget_token_date'])) < DAY_TIMESTAMP && $this->isEmail($input['email']))) { $input["password"] = Auth::getPasswordHash(Toolbox::unclean_cross_side_scripting_deep(stripslashes($input["password"]))); } else { unset($input["password"]); } unset($input["password2"]); } else { Session::addMessageAfterRedirect(__('Error: the two passwords do not match'), false, ERROR); return false; } } } else { if (isset($input["password"])) { // From login unset($input["password"]); } } // Update User in the database if (!isset($input["id"]) && isset($input["name"])) { if ($this->getFromDBbyName($input["name"])) { $input["id"] = $this->fields["id"]; } } if (isset($input["entities_id"]) && Session::getLoginUserID() === $input['id']) { $_SESSION["glpidefault_entity"] = $input["entities_id"]; } // Security on default profile update if (isset($input['profiles_id'])) { if (!in_array($input['profiles_id'], Profile_User::getUserProfiles($input['id']))) { unset($input['profiles_id']); } } // Security on default entity update if (isset($input['entities_id'])) { if (!in_array($input['entities_id'], Profile_User::getUserEntities($input['id']))) { unset($input['entities_id']); } } if (isset($input['_reset_personal_token'])) { $input['personal_token'] = self::getUniquePersonalToken(); $input['personal_token_date'] = $_SESSION['glpi_currenttime']; } // Manage preferences fields if (Session::getLoginUserID() === $input['id']) { if (isset($input['use_mode']) && $_SESSION['glpi_use_mode'] != $input['use_mode']) { $_SESSION['glpi_use_mode'] = $input['use_mode']; //Session::loadLanguage(); } } foreach ($CFG_GLPI['user_pref_field'] as $f) { if (isset($input[$f])) { if (Session::getLoginUserID() === $input['id']) { if ($_SESSION["glpi{$f}"] != $input[$f]) { $_SESSION["glpi{$f}"] = $input[$f]; // reinit translations if ($f == 'language') { $_SESSION['glpi_dropdowntranslations'] = DropdownTranslation::getAvailableTranslations($_SESSION["glpilanguage"]); unset($_SESSION['glpimenu']); } } } if ($input[$f] == $CFG_GLPI[$f]) { $input[$f] = "NULL"; } } } return $input; }
static function selectGroupOnAdd($item) { global $CFG_GLPI, $DB; if (isset($item->input['_auto_import']) || isset($item->input['bypassgrouponadd'])) { return; } $peGroup_group = new self(); if ($_SESSION['glpiactiveprofile']['interface'] == 'central') { $peConfig = new PluginEscalationConfig(); if ($peConfig->getValue('workflow', $item->fields['entities_id']) == '1') { if (isset($_POST['_groups_id_assign']) && $_POST['_groups_id_assign'] > 0) { if (isset($_SESSION['plugin_escalation_files'])) { $_FILES = $_SESSION['plugin_escalation_files']; } return; } else { $group = new Group(); Html::header(__('Administration'), '', "maintain", "ticket"); if (isset($_POST['dropdown__groups_id_requester']) && $_POST['dropdown__groups_id_requester'] > 0) { $_SESSION['plugin_escalation_groups_id_requester'] = $_POST['dropdown__groups_id_requester']; } if (isset($_FILES)) { foreach ($_FILES['filename']['tmp_name'] as $numfile => $datafile) { if ($datafile != '') { $split = explode("/", $datafile); Document::renameForce($datafile, GLPI_DOC_DIR . "/_tmp/" . end($split)); $_FILES['filename']['tmp_name'][$numfile] = GLPI_DOC_DIR . "/_tmp/" . end($split); } } $_SESSION['plugin_escalation_files'] = $_FILES; } echo '<form action="' . $CFG_GLPI['root_doc'] . '/front/ticket.form.php" enctype="multipart/form-data" name="form_ticket" method="post">'; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<th colspan='2'>Sélection du groupe de techniciens</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Group in charge of the ticket') . " :"; echo "</td>"; echo "<td>"; $a_groups = array(); foreach ($_SESSION['glpigroups'] as $groups_id) { $group->getFromDB($groups_id); $a_groups[$groups_id] = $group->getName(); $queryg = "SELECT * FROM `" . $peGroup_group->getTable() . "`\n WHERE `groups_id_source` = '" . $groups_id . "' "; $resultg = $DB->query($queryg); while ($datag = $DB->fetch_array($resultg)) { $group->getFromDB($datag['groups_id_destination']); $a_groups[$groups_id . "_" . $datag['groups_id_destination']] = " > " . $group->getName(); } } $rand = Dropdown::showFromArray("_groups_id_assign_escalation", $a_groups); $params = array('groups_id' => '__VALUE__', 'entity' => $_POST['entities_id'], 'rand' => $rand); Ajax::updateItemOnSelectEvent("dropdown__groups_id_assign" . $rand, "show_assignuser{$rand}", $CFG_GLPI["root_doc"] . "/plugins/escalation/ajax/dropdownUserassign.php", $params); echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'>"; foreach ($_POST as $key => $value) { if (is_array($value)) { foreach ($value as $keyy => $valuee) { echo '<input type="hidden" name="' . $key . '[' . $keyy . ']" value="' . $valuee . '" />'; } } else { if ($key == 'content') { $value = Html::cleanPostForTextArea(Toolbox::clean_cross_side_scripting_deep($value)); echo '<textarea name="' . $key . '" style="display:none;">' . $value . '</textarea>'; } else { if ($key == 'dropdown__groups_id_requester') { echo '<input type="hidden" name="_groups_id_requester" value="' . $value . '" />'; } else { $value = Html::cleanInputText(Toolbox::clean_cross_side_scripting_deep(stripslashes($value))); echo '<input type="hidden" name="' . $key . '" value="' . $value . '" />'; } } } } if (!isset($_POST['_users_id_assign']) or $_POST['_users_id_assign'] == '0') { echo "<span id='show_assignuser{$rand}'></span>"; } echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align='center'>"; echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); Html::footer(); exit; } } } }