Exemplo n.º 1
0
 public static function Save($settings)
 {
     $current = new SettingContainer(DbSetting::GetAll());
     $inners = $settings->getSettings();
     foreach ($inners as $setting) {
         $old = $current->getSetting($setting->name);
         if (!is_int($old)) {
             if (strcmp($old->value, $setting->value) != 0) {
                 DbSetting::Update($setting);
             }
         } else {
             DbSetting::Add($setting->name, $setting->value);
         }
     }
 }
 public function execute()
 {
     $action = 'browse';
     if (isset($_GET['action'])) {
         $action = $_GET['action'];
     }
     if (strcmp($action, 'browse') == 0) {
         $this->view = SettingsAdministrationAction::$BrowseSettings;
     } else {
         if (strcmp($action, 'new_setting') == 0) {
             $this->view = SettingsAdministrationAction::$NewSettingForm;
         } else {
             if (strcmp($action, 'add_setting') == 0) {
                 if (isset($_POST['setting_name']) && isset($_POST['setting_value'])) {
                     DbSetting::Add($_POST['setting_name'], $_POST['setting_value']);
                     $this->addAlert(Alert::CreateSuccess('Success', 'Setting added.'));
                     $this->reloadSettings();
                 }
                 $this->reexecute(array('action' => 'browse'));
             } else {
                 if (strcmp($action, 'delete_setting') == 0) {
                     if (isset($_GET['setting_id'])) {
                         DbSetting::Delete($_GET['setting_id']);
                         $this->addAlert(Alert::CreateSuccess('Success', 'Setting deleted.'));
                         $this->reloadSettings();
                     }
                     $this->reexecute(array('action' => 'browse'));
                 } else {
                     if (strcmp($action, 'save_settings') == 0) {
                         $settings = DbSetting::GetAll();
                         foreach ($settings as $setting) {
                             if (isset($_POST['setting_' . $setting->id])) {
                                 $setting->value = $_POST['setting_' . $setting->id];
                             }
                         }
                         $container = new SettingContainer($settings);
                         DbSetting::Save($container);
                         $this->addAlert(Alert::CreateSuccess('Success', 'Settings saved.'));
                         $this->reloadSettings();
                         $this->reexecute(array('action' => 'browse'));
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public function __construct($constraints = array())
 {
     $this->alerts = array();
     $this->alertRenderer = new AlertRenderer();
     if (isset($_SESSION['alerts'])) {
         //fetching alerts
         //clearing them when they are show
         $this->alerts = $_SESSION['alerts'];
     }
     $this->constraints = $constraints;
     $this->user = new User();
     //todo
     //do some methhods for getBoolConstraint, and other data type
     $no_redirect = $this->getConstraint('no_redirect');
     if (is_int($no_redirect)) {
         $no_redirect = false;
     } else {
         $no_redirect = $no_redirect->value;
     }
     //loading settings
     $settings = DbSetting::GetAll();
     $this->settings = new SettingContainer($settings);
     if ($this->settings->size() == 0) {
         $this->initSettings();
     }
     if (isset($_SESSION['user_id'])) {
         $user_id = $_SESSION['user_id'];
         $this->user->id = $user_id;
         $user = DbUser::GetById($user_id);
         $perms = DbPermission::GetAll();
         $this->permissions = new PermissionContainer($perms);
         if (!$user->isNull()) {
             $this->user = $user;
             //loading permissions
             $userPermissions = DbGroup::GetUserPermissions($this->user->id);
             $this->userPermissions = $userPermissions->getPermissionsInt();
             if ($this->user->isClearPassword()) {
                 //force a password change
                 //todo
                 $no_change = $this->getConstraint("no_change_password");
                 if (!is_int($no_change)) {
                     if (!$no_change->value) {
                         header('location: change_password.php');
                     }
                 } else {
                     header('location: change_password.php');
                 }
             }
         } else {
             //sending the user directly to the login
             if (!$no_redirect) {
                 header('location: login.php');
             }
         }
     } else {
         //sending the user directly to the login
         if (!$no_redirect) {
             header('location: login.php');
         }
     }
 }