Beispiel #1
0
function saction_SetUserStatus()
{
    global $dbHolidays, $dbUsers, $CONFIG, $crlf;
    // Find users with holidays today who don't have correct status
    $success = TRUE;
    $startdate = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
    $enddate = mktime(23, 59, 59, date('m'), date('d'), date('Y'));
    $sql = "SELECT * FROM `{$dbHolidays}` ";
    $sql .= "WHERE `date` >= FROM_UNIXTIME({$startdate}) AND `date` < ";
    $sql .= "FROM_UNIXTIME({$enddate}) AND (type >='" . HOL_HOLIDAY . "' AND type <= " . HOL_FREE . ") ";
    $sql .= "AND (approved=" . HOL_APPROVAL_GRANTED . " OR approved=" . HOL_APPROVAL_DENIED;
    $sql .= " OR approved=" . HOL_APPROVAL_GRANTED_ARCHIVED;
    $sql .= " OR approved=" . HOL_APPROVAL_DENIED_ARCHIVED . ")";
    $result = mysql_query($sql);
    if (mysql_error()) {
        $success = FALSE;
        trigger_error(mysql_error(), E_USER_WARNING);
    }
    while ($huser = mysql_fetch_object($result)) {
        if ($huser->length == 'day' or $huser->length == 'am' and date('H') < 12 or $huser->length == 'pm' and date('H') > 12) {
            $currentstatus = user_status($huser->userid);
            $newstatus = $currentstatus;
            // Only enabled users
            if ($currentstatus > 0) {
                if ($huser->type == HOL_HOLIDAY and $currentstatus != USERSTATUS_ON_HOLIDAY) {
                    $newstatus = USERSTATUS_ON_HOLIDAY;
                }
                if ($huser->type == HOL_SICKNESS and $currentstatus != USERSTATUS_ABSENT_SICK) {
                    $newstatus = USERSTATUS_ABSENT_SICK;
                }
                if ($huser->type == HOL_WORKING_AWAY and ($currentstatus != USERSTATUS_WORKING_FROM_HOME and $currentstatus != USERSTATUS_WORKING_AWAY)) {
                    $newstatus = USERSTATUS_WORKING_AWAY;
                }
                if ($huser->type == HOL_TRAINING and $currentstatus != USERSTATUS_ON_TRAINING_COURSE) {
                    $newstatus = USERSTATUS_ON_TRAINING_COURSE;
                }
                if ($huser->type == HOL_FREE and ($currentstatus != USERSTATUS_NOT_IN_OFFICE and $currentstatus != USERSTATUS_ABSENT_SICK)) {
                    $newstatus = USERSTATUS_ABSENT_SICK;
                }
                // Compassionate
            }
            if ($newstatus != $currentstatus) {
                $accepting = '';
                switch ($newstatus) {
                    case USERSTATUS_IN_OFFICE:
                        $accepting = 'Yes';
                        break;
                    case USERSTATUS_NOT_IN_OFFICE:
                        $accepting = 'No';
                        break;
                    case USERSTATUS_IN_MEETING:
                        // don't change
                        $accepting = '';
                        break;
                    case USERSTATUS_AT_LUNCH:
                        $accepting = '';
                        break;
                    case USERSTATUS_ON_HOLIDAY:
                        $accepting = 'No';
                        break;
                    case USERSTATUS_WORKING_FROM_HOME:
                        $accepting = 'Yes';
                        break;
                    case USERSTATUS_ON_TRAINING_COURSE:
                        $accepting = 'No';
                        break;
                    case USERSTATUS_ABSENT_SICK:
                        $accepting = ' No';
                        break;
                    case USERSTATUS_WORKING_AWAY:
                        // don't change
                        $accepting = '';
                        break;
                    default:
                        $accepting = '';
                }
                $usql = "UPDATE `{$dbUsers}` SET status='{$newstatus}'";
                if ($accepting != '') {
                    $usql .= ", accepting='{$accepting}'";
                }
                $usql .= " WHERE id='{$huser->userid}' LIMIT 1";
                if ($accepting == 'No') {
                    incident_backup_switchover($huser->userid, 'no');
                }
                if ($CONFIG['debug']) {
                    //debug_log(user_realname($huser->userid).': '.userstatus_name($currentstatus).' -> '.userstatus_name($newstatus));
                    //debug_log($usql);
                }
                mysql_query($usql);
                if (mysql_error()) {
                    $success = FALSE;
                    trigger_error(mysql_error(), E_USER_WARNING);
                }
            }
        }
    }
    // Find users who are set away but have no entry in the holiday calendar
    $sql = "SELECT * FROM `{$dbUsers}` WHERE status=" . USERSTATUS_ON_HOLIDAY . " OR ";
    $sql .= "status=" . USERSTATUS_ON_TRAINING_COURSE . " OR ";
    $sql .= "status=" . USERSTATUS_ABSENT_SICK . " OR status=" . USERSTATUS_WORKING_AWAY . " ";
    $result = mysql_query($sql);
    if (mysql_error()) {
        $success = FALSE;
        trigger_error(mysql_error(), E_USER_WARNING);
    }
    return $success;
}
Beispiel #2
0
 /**
  * Updates the details of a user within SiT!
  * @author Paul Heaney
  * @return mixed True if updated sucessfully, String if data validity errors encountered,  FALSE otherwise
  */
 function edit()
 {
     global $now;
     $toReturn = false;
     if (!empty($this->id) and is_number($this > id)) {
         $sql = "SELECT username, status, accepting FROM `{$GLOBALS['dbUsers']}` WHERE id = {$this->id}";
         $result = mysql_query($sql);
         if (mysql_error()) {
             trigger_error(mysql_error(), E_USER_WARNING);
         }
         if (mysql_num_rows($result) == 1) {
             // Exists
             $oldUser = mysql_fetch_object($result);
             $s = array();
             $s[] = "lastseen = NOW()";
             $errors = 0;
             $error_string = '';
             if (!empty($this->password)) {
                 $s[] = "password = MD5('{$this->password}')";
             }
             if (!empty($this->realname)) {
                 $s[] = "realname = '{$this->realname}'";
             }
             if (!empty($this->roleid)) {
                 $s[] = "roleid = {$this->roleid}";
             }
             if (!empty($this->group) and !empty($this->group->id)) {
                 $s[] = "groupid = {$this->group->id}";
             }
             if (!empty($this->jobtitle)) {
                 $s[] = "title = '{$this->jobtitle}'";
             }
             if (!empty($this->signature)) {
                 $s[] = "signature = '{$this->signature}'";
             }
             if (!empty($this->email)) {
                 $sql = "SELECT COUNT(id) FROM `{$GLOBALS['dbUsers']}` WHERE status > 0 AND email='{$this->email}' AND id != {$this->id}";
                 $result = mysql_query($sql);
                 if (mysql_error()) {
                     trigger_error(mysql_error(), E_USER_WARNING);
                 }
                 list($countexisting) = mysql_fetch_row($result);
                 if ($countexisting > 1) {
                     $errors++;
                     $error_string .= "<h5 class='error'>{$GLOBALS['strEmailMustBeUnique']}</h5>\n";
                 }
                 $s[] = "email = '{$this->email}'";
             }
             if (!empty($this->phone)) {
                 $s[] = "phone = '{$this->phone}'";
             }
             if (!empty($this->mobile)) {
                 $s[] = "mobile = '{$this->mobile}'";
             }
             if (!empty($this->fax)) {
                 $s[] = "fax = '{$this->fax}'";
             }
             if (!empty($this->status)) {
                 if ($oldUser->status != $this->status) {
                     // reassign the users incidents if appropriate
                     if (empty($this->accepting)) {
                         $this->accepting = $oldUser->accepting;
                     }
                     // Set accepting to the DB level if one isn't set'
                     incident_backup_switchover($this->id, $ths->accepting);
                 }
                 $s[] = "status = {$this->status}";
             }
             if (!empty($this->message)) {
                 $s[] = "message = '{$this->message}'";
             }
             if (is_bool($this->accepting)) {
                 if ($this->accepting) {
                     $s[] = "accepting = 'Yes'";
                 } else {
                     $s[] = "accepting = 'No'";
                 }
             }
             if (!empty($this->holiday_entitlement)) {
                 $s[] = "holiday_entitlement = {$this->holiday_entitlement}";
             }
             if (!empty($this->holiday_resetdate)) {
                 $s[] = "holiday_restdate = '{$this->holiday_resetdate}'";
             }
             if (!empty($this->qualifications)) {
                 $s[] = "qualifications = '{$this->qualifications}'";
             }
             if (!empty($this->incident_refresh) or $this->incident_refresh === 0) {
                 $s[] = "var_incident_refresh = {$this->incident_refresh}";
             }
             if (!empty($this->update_order)) {
                 $s[] = "var_update_order = '{$this->update_order}'";
             }
             if (!empty($this->num_updates_view)) {
                 $s[] = "var_num_updates_view = {$this->num_updates_view}";
             }
             if (!empty($this->style)) {
                 $s[] = "var_style = {$this->style}";
             }
             if (!empty($this->hide_auto_updates)) {
                 $s[] = "var_hideautoupdates = '{$this->hide_auto_updates}'";
             }
             if (!empty($this->hideheader)) {
                 $s[] = "var_hideheader = '{$this->hideheader}'";
             }
             if (!empty($this->monitor)) {
                 $s[] = "var_monitor = '{$this->monitor}'";
             }
             if (!empty($this->i18n)) {
                 $s[] = "var_i18n = '{$this->i18n}'";
             }
             if (!empty($this->utc_offset) or $this->utc_offset === 0) {
                 $s[] = "var_utc_offset = {$this->utc_offset}";
             }
             if (!empty($this->emoticons)) {
                 $s[] = "var_emoticons = '{$this->emoticons}'";
             }
             if (!empty($this->startdate)) {
                 $s[] = "user_startdate = '{$this->startdate}'";
             }
             if (!empty($this->icq)) {
                 $s[] = "icq = '{$this->icq}'";
             }
             if (!empty($this->aim)) {
                 $s[] = "aim = '{$this->aim}'";
             }
             if (!empty($this->msn)) {
                 $s[] = "msn = '{$this->msn}'";
             }
             if ($errors == 0) {
                 $sql = "UPDATE `{$GLOBALS['dbUsers']}` SET " . implode(", ", $s) . " WHERE id = {$this->id}";
                 $result = mysql_query($sql);
                 if (mysql_error()) {
                     trigger_error(mysql_error(), E_USER_WARNING);
                 }
                 if (mysql_affected_rows() != 1) {
                     trigger_error("Failed to update user", E_USER_WARNING);
                     $toReturn = FALSE;
                 } else {
                     $toReturn = TRUE;
                 }
             } else {
                 $toReturn = $error_string;
             }
         } else {
             $toReturn = FALSE;
         }
     }
     return $toReturn;
 }
             break;
         case 9:
             // Working Away
             // don't change
             $accepting = '';
             break;
     }
     if (!empty($accepting)) {
         $sql .= ", accepting='{$accepting}'";
     }
     $sql .= " WHERE id='{$sit['2']}' LIMIT 1";
     $result = mysql_query($sql);
     if (mysql_error()) {
         trigger_error(mysql_error(), E_USER_ERROR);
     }
     incident_backup_switchover($sit[2], $accepting);
     trigger("TRIGGER_USER_CHANGED_STATUS", array('userid' => $sit[2]));
     header('Location: index.php');
     break;
 case 'setaccepting':
     $sql = "UPDATE `{$dbUsers}` SET accepting='{$accepting}' ";
     $sql .= "WHERE id='{$sit['2']}' LIMIT 1";
     $result = mysql_query($sql);
     if (mysql_error()) {
         trigger_error(mysql_error(), E_USER_ERROR);
     }
     header('Location: index.php');
     break;
 case 'return':
     // dummy entry, just returns user back
     header('Location: index.php');