예제 #1
0
 public function ajax_ssp()
 {
     $this->load_model();
     $db_options = array('table' => '`test`', 'key' => '`id`');
     $test = new cx\database\model($db_options);
     $columns = array(array('db' => "{$db_options['table']}.`id`", 'dt' => 0), array('db' => "{$db_options['table']}.`data`", 'dt' => 1, 'textsize' => 30, 'hyper' => $this->get_url('/app/testing', 'echome', "id="), 'id' => "{$db_options['table']}.`{$db_options['key']}`", 'fn' => 'get_data'));
     $options['where'] = " 1=1";
     $test->ssp_load($columns, $options);
 }
예제 #2
0
 public function edit_user()
 {
     $id = cx\app\static_request::init('get', 'id');
     if ($id->is_not_set()) {
         echo "Invalid id!";
         exit;
     }
     if ($id->to_int() !== $this->session->get_int(CX_LOGIN . 'id')) {
         $this->auth(array('user' => 'admin_check'));
         $lock_rights_controls = false;
         // Admin
     } elseif ($this->auth(array('user' => 'is_admin')) === true) {
         $lock_rights_controls = false;
         // Admin can modify self, as they can create any user...
     } else {
         $lock_rights_controls = true;
         // User must not be able to grant self more rights!
     }
     $this->load_model();
     $db_options = array('table' => 'users', 'key' => 'id');
     $edit_user = new cx\database\model($db_options);
     if ($id->is_not_valid_id()) {
         // no existing data
         $model = array();
         $model['new'] = true;
     } else {
         $edit_user->load($id->to_int());
         $model = $edit_user->get_members();
         if ($model == array()) {
             echo "Invalid id!";
             exit;
         }
         $s_pwd = $model['password'];
         // Save Pwd
         unset($model['password']);
         // Remove scrambled DB password, so user does not see it!
         $model['new'] = false;
     }
     $model['lock_rights_controls'] = $lock_rights_controls;
     $model['rights_statuses'] = array('admin' => 'Administrator', 'staff' => 'Staff', 'cus' => 'Customer', 'api' => 'API client');
     if (cx\app\static_request::init('post', 'save')->is_set()) {
         $edit_user->auto_set_members();
         // Set all post vars to DB
         $confirm = $this->request->post_var('confirm');
         $pwd = $this->request->post_var('password');
         if (cx\app\static_request::init('post', 'username')->is_empty() || cx\app\static_request::init('post', 'fname')->is_empty() || cx\app\static_request::init('post', 'lname')->is_empty()) {
             cx\app\main_functions::set_message('First/Last name or username is missing.');
             $saveme = false;
         } elseif ($model['new'] === false && $this->request->is_empty($confirm) && $this->request->is_empty($pwd)) {
             $edit_user->set_member('password', $s_pwd);
             // Keep current password!
             $saveme = true;
         } elseif ($this->request->is_not_empty($confirm) && $pwd === $confirm && strlen($pwd) > 6) {
             $this->load_model('users' . DS . 'users');
             $db_options = array('api' => false);
             $users = new cx\model\users($db_options);
             $edit_user->set_member('password', $users->get_pwd_hash($pwd));
             // Assign new pwd
             $saveme = true;
         } else {
             cx\app\main_functions::set_message('Password not strong/does not match.');
             $saveme = false;
         }
         if ($saveme === true) {
             $success = $edit_user->save();
             $id = $edit_user->get_member('id');
             if ($success === true && $id > 0) {
                 cx_redirect_url($this->get_url('/app/users', 'edit_user', 'id=' . $id));
             }
         }
     }
     $frm = $this->load_class('cx\\form\\form', array('name' => 'edit_user', 'defaults' => array('readonly' => false)));
     $frm->grab_form('app' . DS . 'users' . DS . 'edit_user', $model);
     $frm->end_form();
     $this->add_js('./assets/pwd-meter.min.js');
     $this->add_css('./assets/login.css');
     $index = $this->get_url('app/users', 'index');
     $this->breadcrumb = array($index => "List Users");
     $this->active_crumb = "Edit User";
     $this->do_view($frm->get_html());
 }