Пример #1
0
 /**
  * Prepares a table output.
  *
  * @param array $filters The associative array containing the filters
  * @return array The usernames matched by the filter
  */
 function _filterUsers($filters)
 {
     // get sqlite handle
     $sqlite = $this->hlp->_getDB();
     if (!$sqlite) {
         return;
     }
     // Get the users for which a row should be displayed
     if (count($filters) > 0) {
         $cnt = 0;
         $sql = "SELECT val.[uid] FROM fieldvals val JOIN fields f ON f.[fid] = val.[fid] WHERE";
         foreach ($filters as $field => $value) {
             if ($cnt > 0) {
                 $sql .= " OR";
             }
             $sql .= " (f.[name] = '" . hsc($field) . "' AND val.[value] = ?)";
             $params[] = $value;
             $cnt++;
         }
         $sql .= " GROUP BY [uid]";
         $res = $sqlite->query($sql, $params);
         $uid_array = $sqlite->res2arr($res);
         foreach ($uid_array as $current) {
             $uids[] = $current['uid'];
         }
         $res = $sqlite->query("SELECT [user] FROM [users] WHERE [uid] IN (" . implode(", ", $uids) . ") ORDER BY [name]");
     } else {
         $res = $sqlite->query("SELECT [user] FROM [users] ORDER BY [name]");
     }
     $users = $sqlite->res2arr($res);
     return $users;
 }
Пример #2
0
 /**
  * Output html of the admin page
  */
 public function html()
 {
     $sqlite = $this->hlp->_getDB();
     if (!$sqlite) {
         return;
     }
     echo $this->locale_xhtml('admin_intro');
     $sql = "SELECT * FROM fields";
     $res = $sqlite->query($sql);
     $rows = $sqlite->res2arr($res);
     $form = new Doku_Form(array('method' => 'post'));
     $form->addHidden('page', 'userprofile_fields');
     $form->addElement('<table class="inline">' . '<tr>' . '<th>' . $this->getLang('name') . '</th>' . '<th>' . $this->getLang('title') . '</th>' . '<th>' . $this->getLang('defaultval') . '</th>' . '</tr>');
     // add empty row for adding a new entry
     $rows[] = array('name' => '', 'title' => '', 'defaultval' => '');
     $cur = 0;
     foreach ($rows as $row) {
         $form->addElement('<tr>');
         $form->addElement('<td>');
         $form->addHidden('up[' . $cur . '][fid]', $row['fid']);
         $form->addElement(form_makeTextField('up[' . $cur . '][name]', $row['name'], ''));
         $form->addElement('</td>');
         $form->addElement('<td>');
         $form->addElement(form_makeTextField('up[' . $cur . '][title]', $row['title'], ''));
         $form->addElement('</td>');
         $form->addElement('<td>');
         $form->addElement(form_makeTextField('up[' . $cur . '][defaultval]', $row['defaultval'], ''));
         $form->addElement('</td>');
         $form->addElement('</tr>');
         $cur++;
     }
     $form->addElement('</table>');
     $form->addElement(form_makeButton('submit', 'admin', $this->getLang('submit')));
     $form->printForm();
 }
 /**
  * Modifies a userprofile page
  * 
  * @param array $params                 the data['params'] component of the AUTH_USER_CHANGE event
  * @param bool $modification_result     the modification was accepted
  *
  * @return void
  */
 private function _modifyProfile($params, $modification_result)
 {
     global $auth;
     // extract event params
     $user = $params[0];
     $changed = $params[1];
     $olduser = null;
     // check if the username was changed
     if (!empty($changed['user']) && $user != $changed['user']) {
         $olduser = $user;
         $user = $changed['user'];
     }
     // get userdata
     $userdata = $auth->getUserData($user, false);
     $noprofile = in_array('noprofile', $userdata['grps']);
     // check noprofile group
     if ($noprofile) {
         // delete user
         $this->hlp->deleteUser($user);
         return;
     }
     // save user
     $uid = $this->hlp->saveUser($user, $userdata['name'], $userdata['mail'], $olduser);
 }
Пример #4
0
 /**
  * Output html of the admin page
  */
 public function html()
 {
     global $ID;
     global $INPUT;
     if (is_null($this->_auth)) {
         print $this->lang['badauth'];
         return false;
     }
     $sqlite = $this->hlp->_getDB();
     if (!$sqlite) {
         return;
     }
     $fn = $INPUT->param('fn');
     if (is_array($fn)) {
         $cmd = key($fn);
         $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null;
     } else {
         $cmd = $fn;
         $param = null;
     }
     $user_list = $this->_auth->retrieveUsers($this->_start, $this->_pagesize, $this->_filter);
     echo $this->locale_xhtml('admin_intro');
     $form = new Doku_Form(array('method' => 'post'));
     $form->addHidden('page', 'userprofile_users');
     // List registered users
     $form->addElement('<table>' . '<tr>' . '<th>' . $this->getLang('username') . '</th>' . '<th>' . $this->getLang('realname') . '</th>' . '<th>' . $this->getLang('email') . '</th>' . '</tr>');
     foreach ($user_list as $user => $userinfo) {
         extract($userinfo);
         /**
          * @var string $name
          * @var string $pass
          * @var string $mail
          * @var array  $grps
          */
         if (!in_array('noprofile', $grps)) {
             $form->addElement('<tr>' . '<td><a href="' . wl($ID, array('fn[edit][' . $user . ']' => 1, 'do' => 'admin', 'page' => 'userprofile_users', 'sectok' => getSecurityToken())) . '" title="' . $this->lang['edit_prompt'] . '">' . hsc($user) . '</a></td>' . '<td>' . hsc($name) . '</td>' . '<td>' . hsc($mail) . '</td>' . '</tr>');
         }
     }
     $form->addElement('</table>');
     // Edit table
     if ($cmd == "edit") {
         $user = $param;
         $profile = $this->hlp->getProfile($user);
         // create hidden fields
         $form->addHidden('up[user][user]', $user);
         $form->addHidden('up[user][name]', $user_list[$user]['name']);
         $form->addHidden('up[user][email]', $user_list[$user]['mail']);
         $sql = "SELECT * FROM fields";
         $res = $sqlite->query($sql);
         $fields = $sqlite->res2arr($res);
         $form->addElement('<table>' . '<tr>' . '<th colspan="2">' . $this->getLang('th_edit') . '</th>' . '</tr>' . '<tr>' . '<td>' . $this->getLang('realname') . '</td>' . '<td>' . hsc($user_list[$user]['name']) . '</td>' . '</tr>' . '<tr>' . '<td>' . $this->getLang('email') . '</td>' . '<td>' . hsc($user_list[$user]['mail']) . '</td>' . '</tr>');
         foreach ($fields as $field) {
             $form->addElement('<tr>');
             $form->addElement('<td>' . hsc($field['title']) . '</td>');
             $form->addElement('<td>');
             $defaults_array = explode('|', $field['defaultval']);
             if (count($defaults_array) > 1) {
                 // create select field
                 $defaults_array = array_map('trim', $defaults_array);
                 $form->addElement(form_makeMenuField('up[data][' . $field['name'] . ']', $defaults_array, $profile[$field['name']], ''));
             } else {
                 // create regular text field
                 $form->addElement(form_makeTextField('up[data][' . $field['name'] . ']', $profile[$field['name']], ''));
             }
             $form->addElement('</td>');
             $form->addElement('</tr>');
         }
         $form->addElement('<tr>' . '<td colspan="2">');
         $form->addElement(form_makeButton('submit', 'admin', $this->getLang('submit')));
         $form->addElement('</td>');
         $form->addElement('</table>');
     }
     $form->printForm();
 }