Ejemplo n.º 1
0
 public function __construct($filterArray = NULL)
 {
     $this->initOperators();
     if ($filterArray != NULL) {
         $this->code = $filterArray[self::FILTER_CODE];
         $this->operator = $this->getOperator($filterArray[self::FILTER_OPERATOR]);
         $this->value = trim($filterArray[self::FILTER_VALUE]);
         $this->timeOffset = Gpf_Session::getInstance()->getTimeOffset();
     }
 }
 public function regenerateLanguageCacheFiles()
 {
     //load langage
     $dbLang = new Gpf_Db_Language();
     $dbLang->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     $dbLang->setCode($this->languageCode);
     $dbLang->setId($dbLang->generateId());
     $dbLang->load();
     $lang = new Gpf_Lang_CsvLanguage();
     $lang->loadFromCsvFile(new Gpf_Io_Csv_Reader(Gpf_Lang_CsvLanguage::getAccountCsvFileName($this->languageCode)));
     $lang->exportAccountCache();
 }
Ejemplo n.º 3
0
 /**
  * @param $request
  * @param $groupId
  * @param $validTo
  * @return string
  */
 public function __construct(Gpf_Rpc_Request $request, Gpf_DateTime $validTo = null)
 {
     parent::__construct();
     $json = new Gpf_Rpc_Json();
     if ($validTo === null) {
         $validTo = new Gpf_DateTime();
         $validTo->addDay(30);
     }
     $this->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     $this->setGroupId('');
     $this->setRequest($json->encode($request->toObject()));
     $this->setValidTo($validTo->toDateTime());
     $this->insert();
     return $this;
 }
	/**
	 * @return Gpf_SqlBuilder_SelectBuilder
	 */
	protected function createSelectBuilder() {
		$selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
		$selectBuilder->select->add(Gpf_Db_Table_Roles::ID, self::ID);
		$selectBuilder->select->add(Gpf_Db_Table_Roles::NAME, self::VALUE);
		$selectBuilder->from->add(Gpf_Db_Table_Roles::getName());

		$accountCondition = new Gpf_SqlBuilder_CompoundWhereCondition();
        if (Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Gpf_Privileges::P_READ) ||
        Gpf_Session::getAuthUser()->hasPrivilege(Pap_Privileges::ROLE_NAME, Pap_Privileges::P_READ)) {
            $accountCondition->add(Gpf_Db_Table_Accounts::ID, '!=', '', 'OR');
        } else {
            $accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', Gpf_Session::getInstance()->getAuthUser()->getAccountId(), 'OR');
        }
		$accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', null, 'OR');
		$selectBuilder->where->addCondition($accountCondition);
		$selectBuilder->where->add(Gpf_Db_Table_Roles::TYPE, '=', Pap_Application::ROLETYPE_MERCHANT);
		$selectBuilder->orderBy->add(Gpf_Db_Table_Accounts::ID);
		$selectBuilder->orderBy->add(Gpf_Db_Table_Roles::NAME);

		return $selectBuilder;
	}
Ejemplo n.º 5
0
 /**
  * @service role add
  * @return Gpf_Rpc_Form
  */
 public function add(Gpf_Rpc_Params $params)
 {
     $form = new Gpf_Rpc_Form($params);
     $origRole = new Gpf_Db_Role();
     $origRole->setId($form->getFieldValue('roleid'));
     $origRole->load();
     $newRole = new Gpf_Db_Role();
     $newRole->setName($form->getFieldValue('name'));
     $newRole->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     $newRole->setRoleType($origRole->getRoleType());
     $newRole->insert();
     if (strlen($origRole->getAccountId())) {
         //it is custom role, copy privileges from db
         $select = new Gpf_SqlBuilder_SelectBuilder();
         $select->select->addConstant($newRole->getId(), 'roleid');
         $select->select->add(Gpf_Db_Table_RolePrivileges::OBJECT, Gpf_Db_Table_RolePrivileges::OBJECT);
         $select->select->add(Gpf_Db_Table_RolePrivileges::PRIVILEGE, Gpf_Db_Table_RolePrivileges::PRIVILEGE);
         $select->from->add(Gpf_Db_Table_RolePrivileges::getName());
         $select->where->add(Gpf_Db_Table_Roles::ID, '=', $origRole->getId());
         $insert = new Gpf_SqlBuilder_InsertBuilder();
         $insert->setTable(Gpf_Db_Table_RolePrivileges::getInstance());
         $insert->fromSelect($select);
         $insert->execute();
     } else {
         //it is default role, copy privileges from php settings
         $privileges = Gpf_Application::getInstance()->getRoleDefaultPrivileges($origRole->getId());
         foreach ($privileges as $objectName => $privilegeList) {
             foreach ($privilegeList as $right) {
                 $privilege = new Gpf_Db_RolePrivilege();
                 $privilege->setRoleId($newRole->getId());
                 $privilege->setObject($objectName);
                 $privilege->setPrivilege($right);
                 $privilege->insert();
             }
         }
     }
     return $form;
 }
Ejemplo n.º 6
0
 /**
  * Get list of roles
  *
  * @service
  * @anonym
  * @param Gpf_Rpc_Params $parmas
  */
 public function getRolesList(Gpf_Rpc_Params $params)
 {
     if (!Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Gpf_Privileges::P_READ) && !Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Pap_Privileges::P_READ_OWN)) {
         throw new Gpf_Rpc_PermissionDeniedException('Gpf_Db_Table_Roles', 'getRolesList');
     }
     $sql = new Gpf_SqlBuilder_SelectBuilder();
     $sql->from->add(Gpf_Db_Table_Roles::getName());
     $sql->select->addAll(Gpf_Db_Table_Roles::getInstance());
     $accountCondition = new Gpf_SqlBuilder_CompoundWhereCondition();
     if (Gpf_Session::getAuthUser()->hasPrivilege(Gpf_Privileges::ROLE, Gpf_Privileges::P_READ)) {
         $accountCondition->add(Gpf_Db_Table_Accounts::ID, '!=', '', 'OR');
     } else {
         $accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', Gpf_Session::getInstance()->getAuthUser()->getAccountId(), 'OR');
     }
     $accountCondition->add(Gpf_Db_Table_Accounts::ID, '=', null, 'OR');
     $sql->where->addCondition($accountCondition);
     if ($params->exists('roleTypes') && $params->get('roleTypes') !== '') {
         $sql->where->add(Gpf_Db_Table_Roles::TYPE, 'IN', explode(',', $params->get('roleTypes')));
     }
     $sql->orderBy->add(Gpf_Db_Table_Accounts::ID);
     $sql->orderBy->add(Gpf_Db_Table_Roles::NAME);
     return $sql->getAllRows();
 }
 public function executeTask()
 {
     $quickTaskId = $_GET['quicktask'];
     if (!$this->existQuickTask($quickTaskId)) {
         $this->output($this->_('Task does not exist!'));
         return;
     }
     $quickTask = $this->getQuickTask($quickTaskId);
     if (!$quickTask->isValid()) {
         $this->output($this->_('Task is not valid!'));
         return;
     }
     $authUser = Gpf::newObj(Gpf_Application::getInstance()->getAuthClass());
     Gpf_Session::getInstance()->save($authUser->createPrivilegedUser());
     try {
         $method = new Gpf_Tasks_QuickTaskRunner_ServiceMethod($quickTask->getRequest());
         $response = $method->execute();
     } catch (Gpf_Exception $e) {
         $this->output($e->getMessage());
         return;
     }
     $this->output($response->toText());
     Gpf_Db_Table_QuickTasks::getInstance()->removeTasksAfterExecute($quickTask);
 }
Ejemplo n.º 8
0
 /**
  * Create private campaigns select builder
  * @return Gpf_SqlBuilder_SelectBuilder
  */
 private function getPrivateCampaignsSqlBuilder() {
     $sqlPrivateCampaigns = new Gpf_SqlBuilder_SelectBuilder();
     $sqlPrivateCampaigns->select->add('cg.campaignid');
     $sqlPrivateCampaigns->from->add(Pap_Db_Table_CommissionGroups::getName(), 'cg');
     $sqlPrivateCampaigns->from->addInnerJoin(Pap_Db_Table_UserInCommissionGroup::getName(), 'uicg',
         "cg.commissiongroupid = uicg.commissiongroupid AND uicg.userid='" . Gpf_Session::getInstance()->getAuthUser()->getPapUserId() . "'");
     $sqlPrivateCampaigns->where->add('uicg.' . Pap_Db_Table_UserInCommissionGroup::STATUS, '=', Pap_Features_PerformanceRewards_Condition::STATUS_APPROVED, 'OR');
     $sqlPrivateCampaigns->where->add('uicg.' . Pap_Db_Table_UserInCommissionGroup::STATUS, '=', Pap_Features_PerformanceRewards_Condition::STATUS_FIXED, 'OR');
     return $sqlPrivateCampaigns;
 }
Ejemplo n.º 9
0
 /**
  *
  * @param Gpf_Install_Manager $instance
  * @return Gpf_Install_Manager
  */
 public static function create(Gpf_Install_Manager $instance)
 {
     Gpf_Session::getInstance()->setVar(Gpf_Paths::INSTALLER, $instance);
     return self::$instance = $instance;
 }
 public function clearCache(){
     $this->cacheArray = array();
     Gpf_Session::getInstance()->setVar('cacheArray',$this->cacheArray);
 }
Ejemplo n.º 11
0
 /**
  * Return download url to file
  *
  * @param string $serverClass Server class name, which will handle download function 
  * @return string
  */
 public function getUrl($serverClass = 'Gpf_File_Download')
 {
     return Gpf_Paths::getInstance()->getBaseServerUrl() . 'scripts/server.php' . '?C=' . $serverClass . '&M=download&S=' . Gpf_Session::getInstance()->getId() . '&FormRequest=Y&FormResponse=Y&fileid=' . $this->getFileId() . '&attachment=Y';
 }
Ejemplo n.º 12
0
 /**
  * Load default username and password in login form
  *
  * @return Gpf_Rpc_Form
  */
 public function loadNoRpc()
 {
     $form = new Gpf_Rpc_Form(new Gpf_Rpc_Params());
     $form->setField(self::REMEMBER_ME, Gpf::YES);
     if (Gpf_Application::isDemo()) {
         $form->setField(self::USERNAME, Gpf_Session::getInstance()->getModule()->getDemoUsername());
         $form->setField(self::PASSWORD, Gpf_Session::getInstance()->getModule()->getDemoPassword());
     }
     $langage = Gpf_Http::getCookie(self::COOKIE_LANGUAGE);
     $form->setField(self::LANGUAGE, $langage, $this->setDefaultLanguage(Gpf_Lang_Languages::getInstance()->getActiveLanguagesNoRpc())->toObject());
     return $form;
 }
Ejemplo n.º 13
0
 /**
  * Load default language for this account
  *
  * @return Gpf_Db_Language
  */
 public function getDefaultLanguage()
 {
     if ($this->defaultLanguage == null) {
         $this->defaultLanguage = new Gpf_Db_Language();
         $this->defaultLanguage->setIsDefault(true);
         $this->defaultLanguage->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
         $this->defaultLanguage->loadFromData(array(Gpf_Db_Table_Accounts::ID, self::IS_DEFAULT));
     }
     return $this->defaultLanguage;
 }
Ejemplo n.º 14
0
 /**
  * @return time zone offset in format +/-HH:MM
  */
 public static function getTimeZoneOffset()
 {
     $timeOffset = Gpf_Session::getInstance()->getTimeOffset();
     $hours = self::addLeadingZero(floor(abs($timeOffset) / 3600));
     $minutes = self::addLeadingZero(floor(abs($timeOffset) % 3600 / 60));
     return $timeOffset < 0 ? '-' : '+' . $hours . ':' . $minutes;
 }
Ejemplo n.º 15
0
 /**
  * Set time offset between client and server and store it to session
  * Offset is computed as client time - server time
  *
  * @anonym
  * @service
  * @param Gpf_Rpc_Params $params
  * @return Gpf_Rpc_Action
  */
 public function syncTime(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     Gpf_Session::getInstance()->setTimeOffset($action->getParam('offset') / 1000);
     $action->addOk();
     return $action;
 }
Ejemplo n.º 16
0
 private function save(){
     Gpf_Session::getInstance()->setVar(self::SESSION_VAR, $this);
 }
Ejemplo n.º 17
0
 public function insert()
 {
     $this->set(Gpf_Db_Table_Tasks::DATECREATED, Gpf_Common_DateUtils::now());
     $this->set(Gpf_Db_Table_Tasks::DATECHANGED, Gpf_Common_DateUtils::now());
     if (is_null($this->getAccountId()) || $this->getAccountId() === '') {
         $this->set(Gpf_Db_Table_Tasks::ACCOUNTID, Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     }
     $this->setProgressMessage($this->_('Waiting'));
     parent::insert();
 }
 /**
  * Import selected language into database and
  * create language cache file in account directory
  */
 protected function importLanguage()
 {
     $langCode = Gpf_Session::getInstance()->getAuthUser()->getLanguage();
     $fileName = Gpf_Paths::getInstance()->getLanguageInstallDirectory() . Gpf_Application::getInstance()->getCode() . '_' . $langCode . '.csv';
     $importer = new Gpf_Lang_ImportLanguageTask($fileName, $langCode);
     $importer->run($this->maxRunTime);
 }
Ejemplo n.º 19
0
 public function localize($message)
 {
     return Gpf_Lang_Dictionary::getInstance(Gpf_Session::getInstance()->getAuthUser()->getLanguage())->get($message);
 }
Ejemplo n.º 20
0
 public function insert()
 {
     try {
         $this->setIsCustom($this->isCustom());
     } catch (Gpf_Exception $e) {
         $this->setIsCustom(false);
     }
     if (!strlen($this->getAccountId())) {
         $this->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     }
     $this->setCreated(Gpf_Common_DateUtils::now());
     return parent::insert();
 }
Ejemplo n.º 21
0
 /**
  * @param String $captchaName - under this name is stored captcha code in session
  */
 private static function getCaptchaText($captchaName)
 {
     return Gpf_Session::getInstance()->getVar(self::SESSION_PREFIX . $captchaName);
 }
Ejemplo n.º 22
0
 public function isInstallModeActive()
 {
     return $this->installMode || Gpf_Session::getInstance()->getVar(self::INSTALLER);
 }
Ejemplo n.º 23
0
 public static function saveAttribute($name, $value, $accountUserId = null)
 {
     $attribute = new Gpf_Db_UserAttribute();
     $attribute->setName($name);
     $attribute->setValue($value);
     if ($accountUserId == null) {
         $attribute->setAccountUserId(Gpf_Session::getInstance()->getAuthUser()->getAccountUserId());
     } else {
         $attribute->setAccountUserId($accountUserId);
     }
     return $attribute->save();
 }
Ejemplo n.º 24
0
	/**
	 * parameter ts should contain client time in format
	 * YYYY-MM-DD_HH:MM:SS
	 *
	 */
	public function computeTimeOffset() {
		if(!isset($_REQUEST['ts']) || $_REQUEST['ts'] == '') {
			return;
		}
		$serverTime = Gpf_Common_DateUtils::now();
		$serverTimestamp = strtotime($serverTime);
		$this->clientDate = str_replace('_', ' ', $_REQUEST['ts']);
		$clientTimestamp = strtotime($this->clientDate);

		$offset = $clientTimestamp - $serverTimestamp;
		$part = ((int)($offset / 900) * 900);
		if ($offset - $part > 450) {
			$part = $part + 900;
		}
		Gpf_Session::getInstance()->setTimeOffset($part);
	}
Ejemplo n.º 25
0
 public function logout()
 {
     Gpf_Log::info($this->_sys('Logged out user %s', $this->getUsername()));
     Gpf_Db_LoginHistory::logLogout();
     $this->clearRememberMeCookie();
     Gpf_Session::getInstance()->destroy();
     Gpf_Plugins_Engine::extensionPoint('Gpf_Auth_User.logout', $this);
 }
Ejemplo n.º 26
0
 private function getTaskFromSession($className, $params)
 {
     if (($tasks = Gpf_Session::getInstance()->getVar($this->getAccountTasksName())) == false) {
         throw new Gpf_Exception($this->getAccountTasksName() . ' not exist');
     }
     if (!array_key_exists($this->getTaskName($className, $params), $tasks)) {
         throw new Gpf_Exception('Task not exist');
     }
     return $tasks[$this->getTaskName($className, $params)];
 }
Ejemplo n.º 27
0
 public static function logLogout()
 {
     try {
         if (!Gpf_Session::getInstance()->getAuthUser()->isLogged()) {
             //user is not logged in, don't monitor his session
             return;
         }
     } catch (Exception $e) {
         return;
     }
     if ($loginId = Gpf_Session::getInstance()->getVar(Gpf_Db_Table_LoginsHistory::ID)) {
         $log = new Gpf_Db_LoginHistory();
         $log->setId($loginId);
         $log->setLogoutTime($log->createDatabase()->getDateString());
         $log->update();
         Gpf_Session::getInstance()->setVar(Gpf_Db_Table_LoginsHistory::ID, false);
     }
 }
Ejemplo n.º 28
0
	private function loginFromCredentials($username, $password){
		$papAlertData = new Pap_Alert_Data();
		$userId = $papAlertData->findUserId($username, $password);

		$user = new Pap_Common_User();
		$user->setId($userId);
		$user->load();
		$roleType = $user->getType();

		Gpf_Session::create();

		$authInfo = new Gpf_Auth_InfoUsernamePassword($username, $password,
		Gpf_Db_Account::DEFAULT_ACCOUNT_ID, $roleType);
		$authUser = new Pap_AuthUser();
		$authUser->load($authInfo);
		Gpf_Session::getInstance()->save($authUser);

		$this->user = $user;
		$this->initializeApplication();
	}
Ejemplo n.º 29
0
 /**
  * Load Wallpaper settings to form
  */
 public function loadNoRpc()
 {
     $form = new Gpf_Rpc_Form();
     $form->addField(self::WALLPAPER, '');
     $form->addField(self::WALLPAPER_POSITION, 'S');
     $form->addField(self::WALLPAPER_TYPE, 'N');
     $form->addField(self::BACKGROUND_COLOR, '#000000');
     try {
         $attributes = Gpf_Db_UserAttribute::getSettingsForGroupOfUsers(array(self::WALLPAPER, self::WALLPAPER_TYPE, self::WALLPAPER_POSITION, self::BACKGROUND_COLOR), array(Gpf_Session::getInstance()->getAuthUser()->getAccountUserId()));
         if (isset($attributes[Gpf_Session::getInstance()->getAuthUser()->getAccountUserId()])) {
             $attributes = $attributes[Gpf_Session::getInstance()->getAuthUser()->getAccountUserId()];
             if (isset($attributes[self::WALLPAPER])) {
                 $form->setField(self::WALLPAPER, $attributes[self::WALLPAPER]);
             }
             if (isset($attributes[self::WALLPAPER_TYPE])) {
                 $form->setField(self::WALLPAPER_TYPE, $attributes[self::WALLPAPER_TYPE]);
             }
             if (isset($attributes[self::WALLPAPER_POSITION])) {
                 $form->setField(self::WALLPAPER_POSITION, $attributes[self::WALLPAPER_POSITION]);
             }
             if (isset($attributes[self::BACKGROUND_COLOR])) {
                 $form->setField(self::BACKGROUND_COLOR, $attributes[self::BACKGROUND_COLOR]);
             }
         }
     } catch (Gpf_Exception $e) {
         $form->setErrorMessage($e->getMessage() . ' ' . $e->getLine());
     }
     return $form;
 }
Ejemplo n.º 30
0
 private function addSessionInfoToCache()
 {
     $sessionInfo = new Gpf_Rpc_Data();
     $sessionInfo->setValue(Gpf_Rpc_Params::SESSION_ID, Gpf_Session::getInstance()->getId());
     $sessionInfo->setValue('loggedUser', Gpf_Session::getAuthUser()->getFirstName() . ' ' . Gpf_Session::getAuthUser()->getLastName());
     $sessionInfo->setValue('loggedUserEmail', Gpf_Session::getAuthUser()->getUsername());
     $sessionInfo->setValue('serverTime', Gpf_DbEngine_Database::getDateString());
     $sessionInfo->setValue('baseUrl', rtrim(Gpf_Paths::getInstance()->getBaseServerUrl(), '/'));
     $this->setSessionInfo($sessionInfo);
     Gpf_Rpc_CachedResponse::addById($sessionInfo, self::SESSION);
 }