"Fossies" - the Fresh Open Source Software Archive

Member "OCSNG_UNIX_SERVER_2.6/ocsreports/plugins/main_sections/ms_users/lib/profile_functions.php" (17 Apr 2019, 4373 Bytes) of package /linux/privat/OCSNG_UNIX_SERVER_2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "profile_functions.php": 2.3.1_vs_2.4.

    1 <?php
    2 /*
    3  * Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors.
    4  * See the Contributors file for more details about them.
    5  *
    6  * This file is part of OCSInventory-NG/OCSInventory-ocsreports.
    7  *
    8  * OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute
    9  * it and/or modify it under the terms of the GNU General Public License as
   10  * published by the Free Software Foundation, either version 2 of the License,
   11  * or (at your option) any later version.
   12  *
   13  * OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it
   14  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  * GNU General Public License for more details.
   17  *
   18  * You should have received a copy of the GNU General Public License
   19  * along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
   20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   21  * MA 02110-1301, USA.
   22  */
   23 require_once 'require/function_users.php';
   24 
   25 function validate_profile_create_form($data) {
   26     global $l;
   27 
   28     $errors = array();
   29     $profiles = get_profile_labels();
   30 
   31     // TODO check for field sizes
   32     // Check mandatory data
   33     $mandatory_fields = array('name', 'label', 'duplicate_profile');
   34     foreach ($mandatory_fields as $field) {
   35         if (!$data[$field]) {
   36             $errors[$field] [] = $l->g(1391);
   37         }
   38     }
   39 
   40     // Check dropdown lists
   41     if ($data['duplicate_profile'] && !isset($profiles[$data['duplicate_profile']])) {
   42         $errors['duplicate_profile'] [] = $l->g(1392);
   43     }
   44 
   45     // Check profile name regex
   46     if ($data['name'] && !preg_match('/^[0-9A-Za-z]+$/', $data['name'])) {
   47         $errors['name'] [] = $l->g(1394);
   48     }
   49 
   50     // Check profile name doesn't exist
   51     if ($data['name'] && isset($profiles[$data['name']])) {
   52         $errors['name'] [] = $l->g(1395);
   53     }
   54 
   55     return $errors;
   56 }
   57 
   58 function validate_profile_edit_form($data) {
   59     global $l;
   60 
   61     $errors = array();
   62 
   63     $yes_no = array('YES', 'NO');
   64 
   65     $urls = $_SESSION['OCS']['url_service'];
   66 
   67     foreach ($data['config'] as $key => $val) {
   68         if (!in_array($val, $yes_no)) {
   69             $errors['config_' . $key . '_'] [] = $l->g(1392);
   70         }
   71     }
   72 
   73     foreach ($data['blacklist'] as $key => $val) {
   74         if (!in_array($val, $yes_no)) {
   75             $errors['blacklist_' . $key . '_'] [] = $l->g(1392);
   76         }
   77     }
   78 
   79     foreach ($data['pages'] as $key => $val) {
   80         if (!$urls->getUrl($key)) {
   81             $errors['blacklist_' . $key . '_'] [] = $l->g(1392);
   82         }
   83     }
   84 
   85     return $errors;
   86 }
   87 
   88 function create_profile($data) {
   89     $profiles = get_profiles();
   90     $newProfile = clone $profiles[$data['duplicate_profile']];
   91 
   92     $newProfile->setName($data['name']);
   93     $newProfile->setLabel($data['label']);
   94 
   95     $serializer = new XMLProfileSerializer();
   96     $xml = $serializer->serialize($newProfile);
   97 
   98     if (file_put_contents(PROFILES_DIR . $newProfile->getName() . '.xml', $xml)) {
   99         return $newProfile->getName();
  100     } else {
  101         return false;
  102     }
  103 }
  104 
  105 function remove_profile($profile_id) {
  106     global $l;
  107 
  108     if (!is_writable(PROFILES_DIR)) {
  109         msg_error($l->g(2116));
  110     } else {
  111         unlink(PROFILES_DIR . $profile_id . '.xml');
  112     }
  113 }
  114 
  115 function update_profile($profile_id, $data) {
  116     $urls = $_SESSION['OCS']['url_service'];
  117 
  118     $profiles = get_profiles();
  119     $profile = $profiles[$profile_id];
  120     $updatedProfile = new Profile($profile_id, $data['new_label'] ?: $profile->getLabel());
  121 
  122     foreach ($data['restrictions'] as $key => $val) {
  123         $updatedProfile->setRestriction($key, $val);
  124     }
  125 
  126     foreach ($data['config'] as $key => $val) {
  127         $updatedProfile->setConfig($key, $val);
  128     }
  129 
  130     foreach ($data['blacklist'] as $key => $val) {
  131         if ($val == 'YES') {
  132             $updatedProfile->addToBlacklist($key);
  133         }
  134     }
  135 
  136     foreach ($data['pages'] as $key => $val) {
  137         if ($urls->getUrl($key) && $val == 'on') {
  138             $updatedProfile->addPage($key);
  139         }
  140     }
  141 
  142     $serializer = new XMLProfileSerializer();
  143     $xml = $serializer->serialize($updatedProfile);
  144 
  145     if (file_put_contents(PROFILES_DIR . $profile->getName() . '.xml', $xml)) {
  146         return $profile->getName();
  147     } else {
  148         return false;
  149     }
  150 }
  151 
  152 ?>