Example #1
0
    }
    $rarr['success'] = !empty($rarr['item']);
    die(json_encode($rarr));
}
// delete item
if (isset($_POST['del_item'])) {
    $item = $db->query('SELECT * FROM users WHERE id=:gid;', array(':gid' => $_POST['del_item']), 'dbRow', true);
    $rarr['success'] = $item->delete();
    $rarr['notify'][] = array('User was successfully deleted', 'User Deleted', 'success');
    die(json_encode($rarr));
}
// check if we are updating a user or creating one
if (isset($_POST['id']) && $_POST['id'] != '') {
    $item = $db->query('SELECT * FROM users WHERE id=:uid;', array(':uid' => $_POST['id']), 'dbRow', true);
    $rarr['notify'][] = array('User was successfully updated', 'User Updated', 'success');
} else {
    $item = new dbRow($db->handle, 'users');
    $rarr['notify'][] = array('User was successfully created', 'User Created', 'success');
}
// save user info
$item->username = $_POST['username'];
$item->groups = isset($_POST['groups']) ? implode(',', $_POST['groups']) : '';
// check if we need to update the password
if (!empty($_POST['password'])) {
    $hash = version_compare(phpversion(), '5.3.7', '>') ? '$2y$12$' : '$1$';
    $salt = substr(strtr(base64_encode(openssl_random_pseudo_bytes(22)), '+', '.'), 0, 22);
    $item->password = crypt($_POST['password'], $hash . $salt);
}
// save the user data to the database
$rarr['success'] = $item->save();
die(json_encode($rarr));
Example #2
0
 /**
  * Returns array of row objects.
  * @param mixed $where  - unlike the other "*Where" methods you may specify a string where clause
  *	@see dbHelper::joinWhere() for $where formatting
  * @param mixed $andor
  *	@see dbHelper::andOr() for more info on $andor formatting
  * @param int $limit
  *
  * @return array(dbRow)
  */
 public function loadRowsWhere($where, $andor = 'AND', $limit = '')
 {
     if (is_array($where)) {
         $where = dbHelper::joinWhere($where, $andor);
     }
     $data = db::qryAssoc("SELECT * FROM {$this->tableName} WHERE {$where} {$limit}");
     //adds to row cache
     dbData::addRows($this->tableName, $this->primaryKey, $data);
     $ret = array();
     foreach ($data as $r) {
         //get loaded from row cache
         $ret[] = dbRow::getRow($this->tableName, $this->primaryKey, $r[$this->primaryKey]);
     }
     return $ret;
 }
Example #3
0
                        username VARCHAR(30) NOT NULL,
                        password CHAR(60),
                        groups VARCHAR(60) NOT NULL
                    );');
            }
            break;
        case '2':
            require 'inc/common/site/database.php';
            require 'inc/classes/database.class.php';
            $db = new database();
            // generate a hash
            $hash = version_compare(phpversion(), '5.3.7', '>') ? '$2y$12$' : '$1$';
            // generate random salt
            $salt = substr(strtr(base64_encode(openssl_random_pseudo_bytes(22)), '+', '.'), 0, 22);
            // add fisrt user
            $udata = new dbRow($db->handle, 'users');
            $udata->username = $_POST['su']['user'];
            $udata->password = crypt($_POST['su']['pass'], $hash . $salt);
            $udata->groups = 'xSU';
            $udata->save();
            break;
    }
    $rarr['success'] = true;
    return_data();
}
// the current step of setup
$step = 1;
// go to next step if file exists
$step += file_exists('inc/common/site/database.php') ? 1 : 0;
// check if we are on step 2
if ($step == 2) {