示例#1
0
 /**
  * @param string $action
  * @return string
  * @access protected
  */
 public function timeClock($action)
 {
     $usr_id = Auth::getUserID();
     // TODO: is the email printing neccessary?
     $email = User::getEmail($usr_id);
     if ($action == 'in') {
         $res = User::clockIn($usr_id);
     } elseif ($action == 'out') {
         $res = User::clockOut($usr_id);
     } else {
         if (User::isClockedIn($usr_id)) {
             $msg = 'is clocked in';
         } else {
             $msg = 'is clocked out';
         }
         return "{$email} {$msg}.\n";
     }
     if ($res == 1) {
         return "{$email} successfully clocked {$action}.\n";
     }
     throw new RemoteApiException("Error clocking {$action}.\n");
 }
示例#2
0
 public function clockUser(&$irc, &$data)
 {
     if (!$this->_isAuthenticated($irc, $data)) {
         return;
     }
     $email = $this->_getEmailByNickname($data->nick);
     $pieces = explode(' ', $data->message);
     if (count($pieces) == 2 && $pieces[1] != 'in' && $pieces[1] != 'out') {
         $this->sendResponse($irc, $data->nick, 'Error: wrong parameter count for "CLOCK" command. Format is "!clock [in|out]".');
         return;
     }
     if (@$pieces[1] == 'in') {
         $res = User::clockIn(User::getUserIDByEmail($email));
     } elseif (@$pieces[1] == 'out') {
         $res = User::clockOut(User::getUserIDByEmail($email));
     } else {
         if (User::isClockedIn(User::getUserIDByEmail($email))) {
             $msg = 'clocked in';
         } else {
             $msg = 'clocked out';
         }
         $this->sendResponse($irc, $data->nick, "You are currently {$msg}.");
         return;
     }
     if ($res == 1) {
         $this->sendResponse($irc, $data->nick, 'Thank you, you are now clocked ' . $pieces[1] . '.');
     } else {
         $this->sendResponse($irc, $data->nick, 'Error clocking ' . $pieces[1] . '.');
     }
 }
示例#3
0
function timeClock($p)
{
    $email = XML_RPC_decode($p->getParam(0));
    $password = XML_RPC_decode($p->getParam(1));
    $auth = authenticate($email, $password);
    if (is_object($auth)) {
        return $auth;
    }
    $action = XML_RPC_decode($p->getParam(2));
    if ($action == "in") {
        $res = User::clockIn(User::getUserIDByEmail($email));
    } elseif ($action == "out") {
        $res = User::clockOut(User::getUserIDByEmail($email));
    } else {
        if (User::isClockedIn(User::getUserIDByEmail($email))) {
            $msg = "is clocked in";
        } else {
            $msg = "is clocked out";
        }
        return new XML_RPC_Response(XML_RPC_Encode("{$email} " . $msg . ".\n"));
    }
    if ($res == 1) {
        return new XML_RPC_Response(XML_RPC_Encode("{$email} successfully clocked " . $action . ".\n"));
    } else {
        return new XML_RPC_Response(0, $XML_RPC_erruser + 1, "Error clocking " . $action . ".\n");
    }
}
示例#4
0
 /**
  * Format is "clock [in|out]"
  *
  * @param Net_SmartIRC $irc
  * @param Net_SmartIRC_data $data
  */
 public final function clock(Net_SmartIRC $irc, Net_SmartIRC_data $data)
 {
     if (!$this->isAuthenticated($data)) {
         return;
     }
     switch (count($data->messageex)) {
         case 1:
             break;
         case 2:
             if (in_array($data->messageex[1], array('in', 'out'))) {
                 break;
             }
             // fall through to an error
         // fall through to an error
         default:
             $this->sendResponse($data->nick, 'Error: wrong parameter count for "CLOCK" command. Format is "!clock [in|out]".');
             return;
     }
     $command = isset($data->messageex[1]) ? $data->messageex[1] : null;
     // FIXME: handle if $email is empty
     $email = $this->bot->getEmailByNickname($data->nick);
     $usr_id = User::getUserIDByEmail($email);
     if ($command == 'in') {
         $res = User::clockIn($usr_id);
     } elseif ($command == 'out') {
         $res = User::clockOut($usr_id);
     } else {
         if (User::isClockedIn($usr_id)) {
             $msg = 'clocked in';
         } else {
             $msg = 'clocked out';
         }
         $this->sendResponse($data->nick, "You are currently {$msg}.");
         return;
     }
     if ($res == 1) {
         $this->sendResponse($data->nick, "Thank you, you are now clocked {$command}.");
     } else {
         $this->sendResponse($data->nick, "Error clocking {$command}.");
     }
 }