method, "list")) { $this->LogList(); } else if (!strcasecmp($this->method, "clear")) { $this->Clear(); } else if (!strcasecmp($this->method, "export")) { $this->Export(); } } private function LogList() { $resp = array(); $params = $this->GetParams_List(); if (!$params) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } $res = PhotoLog::ListItem($params['offset'], $params['limit']); $resp['items'] = $res['data']; $resp['total'] = $res['total']; $offset = (0 > (int)$params['limit']) ? $resp['total'] : $params['offset'] + $params['limit']; $resp['offset'] = ($offset > $resp['total']) ? $resp['total'] : $offset; $this->SetResponse($resp); End: return; } private function Clear() { $params = $this->GetParams_Clear(); if (!$params) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } PhotoLog::Clear($params['user']); End: return; } private function Export() { $params = $this->GetParams_Export(); if (!$params) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } PhotoLog::ExportFile($params['format']); End: return; } private function GetParams_List() { // $variable + 0 => convert to integer $params = array( 'offset' => !isset($_REQUEST['offset']) || $_REQUEST['offset'] < 0 ? 0 : $_REQUEST['offset'] + 0, 'limit' => !isset($_REQUEST['limit']) || $_REQUEST['limit'] < 0 ? NULL : $_REQUEST['limit'] + 0 ); return $params; } private function GetParams_Export() { $format = strtolower($_REQUEST['format']); if (!in_array($format, PhotoLog::$SupportFormat)) { return false; } return array("format" => $format); } private function GetParams_Clear() { $user = $this->GetUser(); if (!$user) { return false; } return array("user" => $user); } private function GetUser() { $user = false; if (isset($_SESSION[SYNOPHOTO_ADMIN_USER]['reg_syno_user'])) { $user = $_SESSION[SYNOPHOTO_ADMIN_USER]['reg_syno_user']; } else if (isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) { $user = ("root" === SYNOPHOTO_ADMIN_USER)? "admin" : SYNOPHOTO_ADMIN_NAME; } return $user; } protected function CheckPermission() { $res = true; $check = array( "list" => $this->operationPemission, "clear" => $this->operationPemission, "export" => $this->operationPemission ); if (!array_key_exists($this->method, $check)) { goto End; } $funcName = "check_".$check[$this->method]; if (!method_exists($this, $funcName)) { $res = false; goto End; } $res = $this->$funcName(); End: if (!$res) { $this->SetError(PHOTOSTATION_LOG_ACCESS_DENY); } return $res; } private function check_admin() { csSYNOPhotoDB::GetDBInstance()->SetSessionCache(); csSYNOPhotoMisc::CheckSessionTimeOut(); return isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']); } } $api = new PhotoLogAPI(); $api->Run(); ?>