/**
  * create the content of recently changed
  * @return string html-content
  * @global Options determine how many days after change the contact should still be shown
  * @param boolean $compact whether list should be displayed with imported link and user who changed contact
  */
 function innerCreate()
 {
     global $db, $CONFIG_DB_PREFIX, $CONFIG_ADMIN_REQUEST_INTERFACE, $CONFIG_ADMIN_REQUEST_BREAKS;
     $db->query("SELECT * FROM `{$CONFIG_DB_PREFIX}AdministrativeRequests` AS request WHERE dateProcessed IS NULL OR ( DATE_ADD(dateProcessed, INTERVAL 14 DAY) >= NOW() )", 'AdministrativeRequest');
     //. TABLE_PROPERTIES . " AS prop
     //WHERE contact.id=prop.id AND prop.label=" . $db->escape($this->featureLabel) . '
     //ORDER BY prop.value ' . ($this->ascending ? 'ASC' : 'DESC') . ($this->limit > 0 ? ' LIMIT '.$this->limit : ''));
     $fields = array('contactId', 'dateAdded', 'requesterId', 'dateProcessed', 'whoProcessedId');
     foreach ($CONFIG_ADMIN_REQUEST_INTERFACE as $k => $v) {
         if (substr($k, 0, 4) != 'html' && $k != 'submit') {
             // not for DB!
             $fields[] = $k;
         }
     }
     $data = array();
     $i = 0;
     while ($c = $db->next('AdministrativeRequest')) {
         $data[$i] = $c;
         if (empty($data[$i]['dateProcessed'])) {
             $id = $data[$i]['requestId'];
             $data[$i]['dateProcessed'] = "<a href='todo?mode=done&id={$id}'>set done</a>";
         }
         if (!empty($data[$i]['whoProcessedId'])) {
             $contact = Contact::newContact($data[$i]['whoProcessedId']);
             $data[$i]['whoProcessedId'] = '<a href="../contact/contact.php?id=' . $contact->contact['id'] . '">' . $contact->contact['lastname'] . (!empty($contact->contact['firstname']) ? ', ' . $contact->contact['firstname'] : '') . '</a>';
         }
         $contact = Contact::newContact($data[$i]['contactId']);
         $data[$i]['contactId'] = '<a href="../contact/contact.php?id=' . $contact->contact['id'] . '">' . $contact->contact['lastname'] . (!empty($contact->contact['firstname']) ? ', ' . $contact->contact['firstname'] : '') . '</a>';
         $contact = Contact::newContact($data[$i]['requesterId']);
         $data[$i]['requesterId'] = '<a href="../contact/contact.php?id=' . $contact->contact['id'] . '">' . $contact->contact['lastname'] . (!empty($contact->contact['firstname']) ? ', ' . $contact->contact['firstname'] : '') . '</a>';
         $i++;
     }
     $cont = '<style>.parr-list { margin: 20px auto 20px auto; width: 90%; } .parr-list th { border: 1px solid; } .parr-list td { border: 1px solid  #AAA; } td.parr-list-tdblank { border: none; } </style>';
     $tGen = new TableGenerator('parr-list', $fields, $CONFIG_ADMIN_REQUEST_BREAKS);
     $cont .= $tGen->generateTable($data, $fields);
     $cont .= '<div><a href="' . Navigation::previousPageUrl() . '">return</a></div><br>';
     return $cont;
 }
 function genHTML($cssClass, $header, $data, $arr, $class = '')
 {
     $cont = '<a name="' . $this->tableName . '"></a>';
     $cont .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . ($this->get ? '?' . $this->get : '') . "#" . $this->tableName . '">';
     // consider if this should be an inline style or better be placed in a stylesheet
     if ($this->saved > 0) {
         $cont .= '<div style="padding: 3px; border: #3399FF 1px solid; border-color: ; background-color: #99FF99;">Successfully saved<b> ' . $this->saved . ' (' . $this->processed . ')</b></div>';
     }
     $cont .= '<input type="hidden" name="' . $this->tableName . '[confirmer]" value="' . $this->tableName . '" />';
     $cont .= '<table>';
     $tableGen = new TableGenerator($cssClass, $header, $this->rowFolding);
     $cont .= $tableGen->generateTable($data, $arr, $class);
     $cont .= '</table>';
     $cont .= '<button id="TableEditorSubmitButton" type="submit">save</button>';
     $cont .= '</form>';
     return $cont;
 }
 /**
  * create the form needed for user management
  * @return string html-content
  * @global DB used for database access
  * @global CONFIG_USER_ACCOUNT_EXPIRED_MAIL email subject and content (mailto:) for expired account message
  * @global CONFIG_USER_ACCOUNT_EXPIRED_INTERVAL SQL interval for DATE_ADD e.g. "1 MONTH" to check account expiration
  */
 function createUserManagementForm()
 {
     global $db, $CONFIG_USER_ACCOUNT_EXPIRED_MAIL, $CONFIG_USER_ACCOUNT_EXPIRED_INTERVAL;
     $cont = '<fieldset class="options-options">';
     $cont .= '<legend>User list</legend>';
     if (empty($CONFIG_USER_ACCOUNT_EXPIRED_INTERVAL)) {
         $CONFIG_USER_ACCOUNT_EXPIRED_INTERVAL = '1 MONTH';
     }
     $db->query("SELECT *, DATE_ADD(lastLogin, INTERVAL {$CONFIG_USER_ACCOUNT_EXPIRED_INTERVAL})<NOW() AS expiredLogin FROM " . TABLE_USERS . ' AS users LEFT JOIN ' . TABLE_CONTACT . ' AS contact ON users.id = contact.id ORDER BY usertype');
     $data = array();
     // collect user types in array for mailto link
     $users = array();
     $managers = array();
     $admins = array();
     while ($r = $db->next()) {
         $email = $r['firstname'] . ' ' . $r['lastname'] . ' <' . $r['reg_email'] . '>';
         $baseHref = '../contact/contact.php?id=' . $r['id'] . '&noxslt=1';
         // no stylesheet display
         $editHref = $baseHref . '&mode=edit';
         if (isset($r['lastname'])) {
             $name = '<a href="' . $baseHref . '">' . $r['lastname'] . ', ' . $r['firstname'] . '</a>&nbsp;(<a href="' . $editHref . '">edit</a>, ' . EmailHelper::sendEmailLink($email, $r['reg_email']) . ')';
         } else {
             $name = EmailHelper::sendEmailLink($email, $email);
         }
         $data[] = array('name' => $name, 'lastLogin' => $r['lastLogin'], 'loginExpired' => $r['expiredLogin'] ? "<a href='mailto:{$email}{$CONFIG_USER_ACCOUNT_EXPIRED_MAIL}'>[!]</a>" : '', 'type' => $r['usertype'], 'delete' => '<a href="javascript:deleteUser(' . $r['userid'] . ')">delete</a>');
         switch ($r['usertype']) {
             case 'admin':
                 $admins[] = $email;
                 break;
             case 'manager':
                 $managers[] = $email;
                 break;
             case 'user':
                 $users[] = $email;
                 break;
         }
     }
     $tableGen = new TableGenerator('admin-users');
     $cont .= $tableGen->generateTable($data, null, '', 'type', false);
     //group by type
     $cont .= '<div><br> Send email to: ' . EmailHelper::sendEmailLink($admins, 'administrators') . '&nbsp;&nbsp;&nbsp;&nbsp;';
     $cont .= EmailHelper::sendEmailLink($managers, 'managers') . '&nbsp;&nbsp;&nbsp;&nbsp;';
     $cont .= EmailHelper::sendEmailLink($users, 'users') . '&nbsp;&nbsp;&nbsp;&nbsp;';
     $cont .= EmailHelper::sendEmailLink(array_merge($managers, $users), 'users and managers') . '&nbsp;&nbsp;&nbsp;&nbsp;';
     $cont .= EmailHelper::sendEmailLink(array_merge($admins, $managers, $users), 'all') . '&nbsp;&nbsp;&nbsp;&nbsp; </div>';
     $cont .= '</fieldset>';
     return $cont;
 }