当前位置: 首页>>代码示例>>PHP>>正文


PHP PluginEvent::set方法代码示例

本文整理汇总了PHP中PluginEvent::set方法的典型用法代码示例。如果您正苦于以下问题:PHP PluginEvent::set方法的具体用法?PHP PluginEvent::set怎么用?PHP PluginEvent::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PluginEvent的用法示例。


在下文中一共展示了PluginEvent::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dispatchPluginModelEvent

 /**
  * method for dispatching plugin events
  *
  * See {@link find()} for detailed explanation about $condition and $params.
  * @param string $sEventName event name to dispatch
  * @param array	$criteria array containing attributes, conditions and params for the filter query
  * @return PluginEvent the dispatched event
  */
 public function dispatchPluginModelEvent($sEventName, $criteria = null)
 {
     $oPluginEvent = new PluginEvent($sEventName, $this);
     $oPluginEvent->set('model', $this->owner);
     if (isset($criteria)) {
         $oPluginEvent->set('filterCriteria', $criteria);
     }
     return App()->getPluginManager()->dispatchEvent($oPluginEvent);
 }
开发者ID:jdbaltazar,项目名称:survey-office,代码行数:17,代码来源:PluginEventBehavior.php

示例2: actionCron

 public function actionCron($interval)
 {
     $pm = \Yii::app()->pluginManager;
     $event = new PluginEvent('cron');
     $event->set('interval', $interval);
     $pm->dispatchEvent($event);
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:7,代码来源:PluginCommand.php

示例3: actionPublicList

 public function actionPublicList($lang = null)
 {
     if (!empty($lang)) {
         App()->setLanguage($lang);
     } else {
         App()->setLanguage(App()->getConfig('defaultlang'));
     }
     $oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttemplate"));
     if ($oTemplate->cssFramework == 'bootstrap') {
         // We now use the bootstrap package isntead of the Yiistrap TbApi::register() method
         // Then instead of using the composer dependency system for templates
         // We can use the package dependency system
         Yii::app()->getClientScript()->registerMetaTag('width=device-width, initial-scale=1.0', 'viewport');
         App()->bootstrap->registerAllScripts();
     }
     $aData = array('publicSurveys' => Survey::model()->active()->open()->public()->with('languagesettings')->findAll(), 'futureSurveys' => Survey::model()->active()->registration()->public()->with('languagesettings')->findAll());
     $htmlOut = $this->render('publicSurveyList', $aData, true);
     $event = new PluginEvent('beforeSurveysStartpageRender', $this);
     $event->set('aData', $aData);
     App()->getPluginManager()->dispatchEvent($event);
     if ($event->get('result')) {
         $htmlFromEvent = $event->get('result');
         $htmlOut = $htmlFromEvent['html'];
     }
     echo $htmlOut;
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:26,代码来源:SurveysController.php

示例4: exportSurvey

 /**
  * Root function for any export results action
  *
  * @param mixed $iSurveyId
  * @param mixed $sLanguageCode
  * @param csv|doc|pdf|xls $sExportPlugin Type of export
  * @param FormattingOptions $oOptions
  * @param string $sFilter 
  */
 function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOptions $oOptions, $sFilter = '')
 {
     //Do some input validation.
     if (empty($iSurveyId)) {
         safeDie('A survey ID must be supplied.');
     }
     if (empty($sLanguageCode)) {
         safeDie('A language code must be supplied.');
     }
     if (empty($oOptions)) {
         safeDie('Formatting options must be supplied.');
     }
     if (empty($oOptions->selectedColumns)) {
         safeDie('At least one column must be selected for export.');
     }
     //echo $oOptions->toString().PHP_EOL;
     $writer = null;
     $iSurveyId = sanitize_int($iSurveyId);
     if ($oOptions->output == 'display') {
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Pragma: public");
     }
     $exports = $this->getExports();
     if (array_key_exists($sExportPlugin, $exports) && !empty($exports[$sExportPlugin])) {
         // This must be a plugin, now use plugin to load the right class
         $event = new PluginEvent('newExport');
         $event->set('type', $sExportPlugin);
         $oPluginManager = App()->getPluginManager();
         $oPluginManager->dispatchEvent($event, $exports[$sExportPlugin]);
         $writer = $event->get('writer');
     }
     if (!$writer instanceof IWriter) {
         throw new Exception(sprintf('Writer for %s should implement IWriter', $sExportPlugin));
     }
     $surveyDao = new SurveyDao();
     $survey = $surveyDao->loadSurveyById($iSurveyId, $sLanguageCode);
     $writer->init($survey, $sLanguageCode, $oOptions);
     $surveyDao->loadSurveyResults($survey, $oOptions->responseMinRecord, $oOptions->responseMaxRecord, $sFilter, $oOptions->responseCompletionState);
     $writer->write($survey, $sLanguageCode, $oOptions, true);
     $result = $writer->close();
     // Close resultset if needed
     if ($survey->responses instanceof CDbDataReader) {
         $survey->responses->close();
     }
     if ($oOptions->output == 'file') {
         return $writer->filename;
     } else {
         return $result;
     }
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:59,代码来源:exportresults_helper.php

示例5: authenticate

 public function authenticate()
 {
     // First initialize the result, we can later retieve it to get the exact error code/message
     $result = new LSAuthResult(self::ERROR_NONE);
     // Check if the ip is locked out
     if (FailedLoginAttempt::model()->isLockedOut()) {
         $message = sprintf(gT('You have exceeded the number of maximum login attempts. Please wait %d minutes before trying again.'), App()->getConfig('timeOutTime') / 60);
         $result->setError(self::ERROR_IP_LOCKED_OUT, $message);
     }
     // If still ok, continue
     if ($result->isValid()) {
         if (is_null($this->plugin)) {
             $result->setError(self::ERROR_UNKNOWN_HANDLER);
         } else {
             // Delegate actual authentication to plugin
             $authEvent = new PluginEvent('newUserSession', $this);
             $authEvent->set('identity', $this);
             App()->getPluginManager()->dispatchEvent($authEvent, array($this->plugin));
             $pluginResult = $authEvent->get('result');
             if ($pluginResult instanceof LSAuthResult) {
                 //print_r($pluginResult);
                 $result = $pluginResult;
             } else {
                 //echo 'out result';
                 $result->setError(self::ERROR_UNKNOWN_IDENTITY);
             }
         }
     }
     if ($result->isValid()) {
         // Perform postlogin
         //exit('you are in post login');
         $this->postLogin();
     } else {
         // Log a failed attempt
         //exit('you login failed');
         $userHostAddress = App()->request->getUserHostAddress();
         FailedLoginAttempt::model()->addAttempt($userHostAddress);
         App()->session->regenerateID();
         // Handled on login by Yii
     }
     $this->errorCode = $result->getCode();
     $this->errorMessage = $result->getMessage();
     return $result->isValid();
 }
开发者ID:jdbaltazar,项目名称:survey-office,代码行数:44,代码来源:LSUserIdentity.php

示例6: setPermissions

 /**
  * Sets permissions (global or survey-specific) for a survey administrator
  * Checks what permissions may be set and automatically filters invalid ones. 
  * A permission may be invalid if the permission does not exist or that particular user may not give that permission
  * 
  * @param mixed $iUserID
  * @param mixed $iEntityID
  * @param mixed $sEntityName
  * @param mixed $aPermissions
  * @param mixed $bBypassCheck
  */
 public static function setPermissions($iUserID, $iEntityID, $sEntityName, $aPermissions, $bBypassCheck = false)
 {
     $iUserID = sanitize_int($iUserID);
     // Filter global permissions on save
     if ($sEntityName == 'global') {
         $aBasePermissions = Permission::model()->getGlobalBasePermissions();
         if (!Permission::model()->hasGlobalPermission('superadmin', 'read') && !$bBypassCheck) {
             // if not superadmin filter the available permissions as no admin may give more permissions than he owns
             // Make sure that he owns the user he wants to give global permissions for
             $oUser = User::model()->findByAttributes(array('uid' => $iUserID, 'parent_id' => Yii::app()->session['loginID']));
             if (!$oUser) {
                 die('You are not allowed to set permisisons for this user');
             }
             $aFilteredPermissions = array();
             foreach ($aBasePermissions as $PermissionName => $aPermission) {
                 foreach ($aPermission as $sPermissionKey => &$sPermissionValue) {
                     if ($sPermissionKey != 'title' && $sPermissionKey != 'img' && !Permission::model()->hasGlobalPermission($PermissionName, $sPermissionKey)) {
                         $sPermissionValue = false;
                     }
                 }
                 // Only have a row for that permission if there is at least one permission he may give to other users
                 if ($aPermission['create'] || $aPermission['read'] || $aPermission['update'] || $aPermission['delete'] || $aPermission['import'] || $aPermission['export']) {
                     $aFilteredPermissions[$PermissionName] = $aPermission;
                 }
             }
             $aBasePermissions = $aFilteredPermissions;
         } elseif (Permission::model()->hasGlobalPermission('superadmin', 'read') && Yii::app()->session['loginID'] != 1) {
             unset($aBasePermissions['superadmin']);
         }
     } elseif ($sEntityName == 'survey') {
         $aBasePermissions = Permission::model()->getSurveyBasePermissions();
     }
     $aFilteredPermissions = array();
     foreach ($aBasePermissions as $sPermissionname => $aPermission) {
         $aFilteredPermissions[$sPermissionname]['create'] = isset($aPermissions[$sPermissionname]['create']) && $aPermissions[$sPermissionname]['create'];
         $aFilteredPermissions[$sPermissionname]['read'] = isset($aPermissions[$sPermissionname]['read']) && $aPermissions[$sPermissionname]['read'];
         $aFilteredPermissions[$sPermissionname]['update'] = isset($aPermissions[$sPermissionname]['update']) && $aPermissions[$sPermissionname]['update'];
         $aFilteredPermissions[$sPermissionname]['delete'] = isset($aPermissions[$sPermissionname]['delete']) && $aPermissions[$sPermissionname]['delete'];
         $aFilteredPermissions[$sPermissionname]['import'] = isset($aPermissions[$sPermissionname]['import']) && $aPermissions[$sPermissionname]['import'];
         $aFilteredPermissions[$sPermissionname]['export'] = isset($aPermissions[$sPermissionname]['export']) && $aPermissions[$sPermissionname]['export'];
     }
     $condition = array('entity_id' => $iEntityID, 'uid' => $iUserID);
     $oEvent = new PluginEvent('beforePermissionSetSave');
     $oEvent->set('aNewPermissions', $aFilteredPermissions);
     $oEvent->set('iSurveyID', $iEntityID);
     $oEvent->set('iUserID', $iUserID);
     $result = App()->getPluginManager()->dispatchEvent($oEvent);
     // Only the original superadmin may change the superadmin permissions
     if (Yii::app()->session['loginID'] != 1) {
         Permission::model()->deleteAllByAttributes($condition, "permission <> 'superadmin'");
     } else {
         Permission::model()->deleteAllByAttributes($condition);
     }
     foreach ($aFilteredPermissions as $sPermissionname => $aPermission) {
         if ($aPermission['create'] || $aPermission['read'] || $aPermission['update'] || $aPermission['delete'] || $aPermission['import'] || $aPermission['export']) {
             $data = array('entity_id' => $iEntityID, 'entity' => $sEntityName, 'uid' => $iUserID, 'permission' => $sPermissionname, 'create_p' => (int) $aPermission['create'], 'read_p' => (int) $aPermission['read'], 'update_p' => (int) $aPermission['update'], 'delete_p' => (int) $aPermission['delete'], 'import_p' => (int) $aPermission['import'], 'export_p' => (int) $aPermission['export']);
             $permission = new self();
             foreach ($data as $k => $v) {
                 $permission->{$k} = $v;
             }
             $permission->save();
         }
     }
     return true;
 }
开发者ID:jdbaltazar,项目名称:survey-office,代码行数:76,代码来源:Permission.php

示例7: menuMain

 protected function menuMain()
 {
     $title = CHtml::tag('strong', array(), gT('Administration'));
     if (Yii::app()->session['loginID']) {
         $title .= ' -- ' . gT("Logged in as:");
         $text = ' ' . Yii::app()->session['user'] . ' ' . CHtml::image(Yii::app()->getConfig('adminimageurl') . 'profile_edit.png', gT("Edit your personal preferences"));
         $title .= CHtml::tag('strong', array(), CHtml::link($text, array('admin/user', 'sa' => 'personalsettings')));
     }
     $menu['title'] = CHtml::tag('div', array('class' => 'menubar-title-left'), $title);
     $menu['role'] = 'main';
     $menu['imageUrl'] = App()->getConfig('adminimageurl');
     $menu['items']['left'][] = array('href' => array('admin/survey'), 'alt' => gT('Default administration page'), 'image' => 'home.png');
     $menu['items']['left'][] = 'separator';
     if (Permission::model()->hasGlobalPermission('users', 'read')) {
         $menu['items']['left'][] = array('href' => array('admin/user'), 'alt' => gT('Manage survey administrators'), 'image' => 'security.png');
     }
     $menu['items']['left'][] = $this->userGroups();
     $menu['items']['left'][] = $this->globalSettings();
     $menu['items']['left'][] = 'separator';
     $menu['items']['left'][] = $this->checkIntegrity();
     $menu['items']['left'][] = $this->dumpDatabase();
     $menu['items']['left'][] = 'separator';
     $menu['items']['left'][] = $this->editLabels();
     $menu['items']['left'][] = 'separator';
     $menu['items']['left'][] = $this->editTemplates();
     $menu['items']['left'][] = 'separator';
     $menu['items']['left'][] = $this->participantDatabase();
     $menu['items']['left'][] = $this->pluginManager();
     $surveys = getSurveyList(true);
     $tmpList = array();
     $timeadjust = getGlobalSetting('timeadjust');
     foreach ($surveys as $survey) {
         if ($survey['active'] != 'Y') {
             $group = gT("Inactive");
             $list = 'inactive';
         } elseif ($survey['expires'] != '' && $survey['expires'] < dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)) {
             $group = gT("Expired");
             $list = 'expired';
         } else {
             $group = gT("Active");
             $list = 'active';
         }
         $tmpList[$list][] = array('id' => $survey['sid'], 'title' => $survey['surveyls_title'], 'group' => $group);
     }
     $surveyList = array();
     if (array_key_exists('active', $tmpList)) {
         $surveyList = array_merge($surveyList, $tmpList['active']);
     }
     if (array_key_exists('expired', $tmpList)) {
         $surveyList = array_merge($surveyList, $tmpList['expired']);
     }
     if (array_key_exists('inactive', $tmpList)) {
         $surveyList = array_merge($surveyList, $tmpList['inactive']);
     }
     $menu['items']['right'][] = array('title' => gT('Surveys:'), 'type' => 'select', 'name' => 'surveyid', 'route' => 'admin/survey/sa/view', 'param' => 'surveyid', 'empty' => gT('No surveys available.'), 'values' => $surveyList, 'value' => $this->surveyId);
     $menu['items']['right'][] = array('href' => array('admin/survey', 'sa' => 'index'), 'alt' => gT('Detailed list of surveys'), 'image' => 'surveylist.png');
     $menu['items']['right'][] = $this->createSurvey();
     $menu['items']['right'][] = 'separator';
     $menu['items']['right'][] = array('href' => array('admin/authentication', 'sa' => 'logout'), 'alt' => gT('Logout'), 'image' => 'logout.png');
     $menu['items']['right'][] = array('href' => "http://docs.limesurvey.org", 'alt' => gT('LimeSurvey online manual'), 'image' => 'showhelp.png');
     $event = new PluginEvent('afterAdminMenuLoad', $this);
     $event->set('menu', $menu);
     $result = App()->getPluginManager()->dispatchEvent($event);
     $menu = $result->get('menu');
     return $menu;
 }
开发者ID:BertHankes,项目名称:LimeSurvey,代码行数:66,代码来源:MenuWidget.php

示例8: run

    function run($actionID)
    {
        $surveyid = Yii::app()->session['LEMsid'];
        $oSurvey = Survey::model()->findByPk($surveyid);
        if (!$oSurvey) {
            throw new CHttpException(400);
        }
        // See for debug > 1
        $sLanguage = isset(Yii::app()->session['survey_' . $surveyid]['s_lang']) ? Yii::app()->session['survey_' . $surveyid]['s_lang'] : "";
        $uploaddir = Yii::app()->getConfig("uploaddir");
        $tempdir = Yii::app()->getConfig("tempdir");
        Yii::app()->loadHelper("database");
        // Fill needed var
        $sFileGetContent = Yii::app()->request->getParam('filegetcontents', '');
        // The file to view fu_ or fu_tmp
        $bDelete = Yii::app()->request->getParam('delete');
        $sFieldName = Yii::app()->request->getParam('fieldname');
        $sFileName = Yii::app()->request->getParam('filename', '');
        // The file to delete fu_ or fu_tmp
        $sOriginalFileName = Yii::app()->request->getParam('name', '');
        // Used for javascript return only
        $sMode = Yii::app()->request->getParam('mode');
        $sPreview = Yii::app()->request->getParam('preview', 0);
        // Validate and filter and throw error if problems
        // Using 'futmp_'.randomChars(15).'_'.$pathinfo['extension'] for filename, then remove all other characters
        $sFileGetContentFiltered = preg_replace('/[^a-zA-Z0-9_]/', '', $sFileGetContent);
        $sFileNameFiltered = preg_replace('/[^a-zA-Z0-9_]/', '', $sFileName);
        $sFieldNameFiltered = preg_replace('/[^X0-9]/', '', $sFieldName);
        if ($sFileGetContent != $sFileGetContentFiltered || $sFileName != $sFileNameFiltered || $sFieldName != $sFieldNameFiltered) {
            // If one seems to be a hack: Bad request
            throw new CHttpException(400);
            // See for debug > 1
        }
        if ($sFileGetContent) {
            if (substr($sFileGetContent, 0, 6) == 'futmp_') {
                $sFileDir = $tempdir . '/upload/';
            } elseif (substr($sFileGetContent, 0, 3) == 'fu_') {
                // Need to validate $_SESSION['srid'], and this file is from this srid !
                $sFileDir = "{$uploaddir}/surveys/{$surveyid}/files/";
            } else {
                throw new CHttpException(400);
                // See for debug > 1
            }
            if (is_file($sFileDir . $sFileGetContent)) {
                header('Content-Type: ' . CFileHelper::getMimeType($sFileDir . $sFileGetContent));
                readfile($sFileDir . $sFileGetContent);
                Yii::app()->end();
            } else {
                Yii::app()->end();
            }
        } elseif ($bDelete) {
            if (substr($sFileName, 0, 6) == 'futmp_') {
                $sFileDir = $tempdir . '/upload/';
            } elseif (substr($sFileName, 0, 3) == 'fu_') {
                // Need to validate $_SESSION['srid'], and this file is from this srid !
                $sFileDir = "{$uploaddir}/surveys/{$surveyid}/files/";
            } else {
                throw new CHttpException(400);
                // See for debug > 1
            }
            if (isset($_SESSION[$sFieldName])) {
                // We already have $sFieldName ?
                $sJSON = $_SESSION[$sFieldName];
                $aFiles = json_decode(stripslashes($sJSON), true);
                if (substr($sFileName, 0, 3) == 'fu_') {
                    $iFileIndex = 0;
                    $found = false;
                    foreach ($aFiles as $aFile) {
                        if ($aFile['filename'] == $sFileName) {
                            $found = true;
                            break;
                        }
                        $iFileIndex++;
                    }
                    if ($found == true) {
                        unset($aFiles[$iFileIndex]);
                    }
                    $_SESSION[$sFieldName] = ls_json_encode($aFiles);
                }
            }
            //var_dump($sFileDir.$sFilename);
            // Return some json to do a beautiful text
            if (@unlink($sFileDir . $sFileName)) {
                echo sprintf(gT('File %s deleted'), $sOriginalFileName);
            } else {
                echo gT('Oops, There was an error deleting the file');
            }
            Yii::app()->end();
        }
        if ($sMode == "upload") {
            $sTempUploadDir = $tempdir . '/upload/';
            // Check if exists and is writable
            if (!file_exists($sTempUploadDir)) {
                // Try to create
                mkdir($sTempUploadDir);
            }
            $filename = $_FILES['uploadfile']['name'];
            // Do we filter file name ? It's used on displaying only , but not save like that.
            //$filename = sanitize_filename($_FILES['uploadfile']['name']);// This remove all non alpha numeric characters and replaced by _ . Leave only one dot .
            $size = 0.001 * $_FILES['uploadfile']['size'];
//.........这里部分代码省略.........
开发者ID:jordan095,项目名称:pemiluweb-iadel,代码行数:101,代码来源:UploaderController.php

示例9: actionUnsecure

 /**
  * Launch the event newUnsecureRequest
  * @param $plugin : the target
  * @param $function : the function to call from the plugin
  */
 public function actionUnsecure($plugin, $function = null)
 {
     $oEvent = new PluginEvent('newUnsecureRequest');
     // The intended target of the call.
     $oEvent->set('target', $plugin);
     // The name of the function.
     $oEvent->set('function', $function);
     $oEvent->set('request', App()->request);
     App()->getPluginManager()->dispatchEvent($oEvent);
     $sOutput = '';
     foreach ($oEvent->getAllContent() as $content) {
         $sOutput .= $content->getContent();
     }
     if (!empty($sOutput)) {
         $this->renderText($sOutput);
     }
 }
开发者ID:sickpig,项目名称:LimeSurvey,代码行数:22,代码来源:PluginsController.php

示例10: email

 /**
  * Handle email action
  */
 function email($iSurveyId, $tokenids = null)
 {
     $clang = $this->getController()->lang;
     $iSurveyId = sanitize_int($iSurveyId);
     if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update')) {
         Yii::app()->session['flashmessage'] = $clang->gT("You do not have sufficient rights to access this page.");
         $this->getController()->redirect(array("/admin/survey/sa/view/surveyid/{$iSurveyId}"));
     }
     // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
     $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
     if (!$bTokenExists) {
         self::_newtokentable($iSurveyId);
     }
     $aTokenIds = $tokenids;
     if (empty($tokenids)) {
         $aTokenIds = Yii::app()->request->getPost('tokenids', false);
     }
     if (!empty($aTokenIds)) {
         $aTokenIds = explode('|', $aTokenIds);
         $aTokenIds = array_filter($aTokenIds);
         $aTokenIds = array_map('sanitize_int', $aTokenIds);
     }
     $aTokenIds = array_unique(array_filter((array) $aTokenIds));
     $sSubAction = Yii::app()->request->getParam('action');
     $sSubAction = !in_array($sSubAction, array('email', 'remind')) ? 'email' : $sSubAction;
     $bEmail = $sSubAction == 'email';
     Yii::app()->loadHelper('surveytranslator');
     Yii::app()->loadHelper('/admin/htmleditor');
     Yii::app()->loadHelper('replacements');
     $token = Token::model($iSurveyId)->find();
     $aExampleRow = isset($token) ? $token->attributes : array();
     $aSurveyLangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages;
     $sBaseLanguage = Survey::model()->findByPk($iSurveyId)->language;
     array_unshift($aSurveyLangs, $sBaseLanguage);
     $aTokenFields = getTokenFieldsAndNames($iSurveyId, true);
     $iAttributes = 0;
     $bHtml = getEmailFormat($iSurveyId) == 'html';
     $timeadjust = Yii::app()->getConfig("timeadjust");
     $aData['thissurvey'] = getSurveyInfo($iSurveyId);
     foreach ($aSurveyLangs as $sSurveyLanguage) {
         $aData['thissurvey'][$sSurveyLanguage] = getSurveyInfo($iSurveyId, $sSurveyLanguage);
     }
     $aData['surveyid'] = $iSurveyId;
     $aData['sSubAction'] = $sSubAction;
     $aData['bEmail'] = $bEmail;
     $aData['aSurveyLangs'] = $aData['surveylangs'] = $aSurveyLangs;
     $aData['baselang'] = $sBaseLanguage;
     $aData['tokenfields'] = array_keys($aTokenFields);
     $aData['nrofattributes'] = $iAttributes;
     $aData['examplerow'] = $aExampleRow;
     $aData['tokenids'] = $aTokenIds;
     $aData['ishtml'] = $bHtml;
     $iMaxEmails = Yii::app()->getConfig('maxemails');
     if (Yii::app()->request->getPost('bypassbademails') == 'Y') {
         $SQLemailstatuscondition = "emailstatus = 'OK'";
     } else {
         $SQLemailstatuscondition = "emailstatus <> 'OptOut'";
     }
     if (!Yii::app()->request->getPost('ok')) {
         if (empty($aData['tokenids'])) {
             $aTokens = TokenDynamic::model($iSurveyId)->findUninvitedIDs($aTokenIds, 0, $bEmail, $SQLemailstatuscondition);
             foreach ($aTokens as $aToken) {
                 $aData['tokenids'][] = $aToken;
             }
         }
         $this->_renderWrappedTemplate('token', array('tokenbar', $sSubAction), $aData);
     } else {
         $SQLremindercountcondition = "";
         $SQLreminderdelaycondition = "";
         if (!$bEmail) {
             if (Yii::app()->request->getPost('maxremindercount') && Yii::app()->request->getPost('maxremindercount') != '' && intval(Yii::app()->request->getPost('maxremindercount')) != 0) {
                 $SQLremindercountcondition = "remindercount < " . intval(Yii::app()->request->getPost('maxremindercount'));
             }
             if (Yii::app()->request->getPost('minreminderdelay') && Yii::app()->request->getPost('minreminderdelay') != '' && intval(Yii::app()->request->getPost('minreminderdelay')) != 0) {
                 // Yii::app()->request->getPost('minreminderdelay') in days (86400 seconds per day)
                 $compareddate = dateShift(date("Y-m-d H:i:s", time() - 86400 * intval(Yii::app()->request->getPost('minreminderdelay'))), "Y-m-d H:i", $timeadjust);
                 $SQLreminderdelaycondition = " ( " . " (remindersent = 'N' AND sent < '" . $compareddate . "') " . " OR " . " (remindersent < '" . $compareddate . "'))";
             }
         }
         $ctresult = TokenDynamic::model($iSurveyId)->findUninvitedIDs($aTokenIds, 0, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
         $ctcount = count($ctresult);
         $emresult = TokenDynamic::model($iSurveyId)->findUninvited($aTokenIds, $iMaxEmails, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
         $emcount = count($emresult);
         foreach ($aSurveyLangs as $language) {
             // See #08683 : this allow use of {TOKEN:ANYTHING}, directly replaced by {ANYTHING}
             $sSubject[$language] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", Yii::app()->request->getPost('subject_' . $language));
             $sMessage[$language] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", Yii::app()->request->getPost('message_' . $language));
             if ($bHtml) {
                 $sMessage[$language] = html_entity_decode($sMessage[$language], ENT_QUOTES, Yii::app()->getConfig("emailcharset"));
             }
         }
         $attributes = array_keys(getTokenFieldsAndNames($iSurveyId, true));
         $tokenoutput = "";
         if ($emcount > 0) {
             foreach ($emresult as $emrow) {
                 $to = $fieldsarray = array();
                 $aEmailaddresses = explode(';', $emrow['email']);
//.........这里部分代码省略.........
开发者ID:josetorerobueno,项目名称:test_repo,代码行数:101,代码来源:tokens.php

示例11: fetchExtraMenus

 /**
  * Get extra menus from plugins that are using event beforeAdminMenuRender
  *
  * @param array $aData
  * @return array<ExtraMenu>
  */
 protected function fetchExtraMenus(array $aData)
 {
     $event = new PluginEvent('beforeAdminMenuRender', $this);
     $event->set('data', $aData);
     $result = App()->getPluginManager()->dispatchEvent($event);
     $extraMenus = $result->get('extraMenus');
     if ($extraMenus === null) {
         $extraMenus = array();
     }
     return $extraMenus;
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:17,代码来源:Survey_Common_Action.php

示例12: checkCompletedQuota

/**
* checkCompletedQuota() returns matched quotas information for the current response
* @param integer $surveyid - Survey identification number
* @param bool $return - set to true to return information, false do the quota
* @return array - nested array, Quotas->Members->Fields, includes quota information matched in session.
*/
function checkCompletedQuota($surveyid, $return = false)
{
    if (!isset($_SESSION['survey_' . $surveyid]['srid'])) {
        return;
    }
    static $aMatchedQuotas;
    // EM call 2 times quotas with 3 lines of php code, then use static.
    if (!$aMatchedQuotas) {
        $aMatchedQuotas = array();
        $quota_info = $aQuotasInfo = getQuotaInformation($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
        // $aQuotasInfo have an 'active' key, we don't use it ?
        if (!$aQuotasInfo || empty($aQuotasInfo)) {
            return $aMatchedQuotas;
        }
        // Test only completed quota, other is not needed
        $aQuotasCompleted = array();
        foreach ($aQuotasInfo as $aQuotaInfo) {
            $iCompleted = getQuotaCompletedCount($surveyid, $aQuotaInfo['id']);
            // Return a string
            if (ctype_digit($iCompleted) && (int) $iCompleted >= (int) $aQuotaInfo['qlimit']) {
                // This remove invalid quota and not completed
                $aQuotasCompleted[] = $aQuotaInfo;
            }
        }
        if (empty($aQuotasCompleted)) {
            return $aMatchedQuotas;
        }
        // OK, we have some quota, then find if this $_SESSION have some set
        $aPostedFields = explode("|", Yii::app()->request->getPost('fieldnames', ''));
        // Needed for quota allowing update
        foreach ($aQuotasCompleted as $aQuotaCompleted) {
            $iMatchedAnswers = 0;
            $bPostedField = false;
            // Array of field with quota array value
            $aQuotaFields = array();
            // Array of fieldnames with relevance value : EM fill $_SESSION with default value even is unrelevant (em_manager_helper line 6548)
            $aQuotaRelevantFieldnames = array();
            foreach ($aQuotaCompleted['members'] as $aQuotaMember) {
                $aQuotaFields[$aQuotaMember['fieldname']][] = $aQuotaMember['value'];
                $aQuotaRelevantFieldnames[$aQuotaMember['fieldname']] = isset($_SESSION['survey_' . $surveyid]['relevanceStatus'][$aQuotaMember['qid']]) && $_SESSION['survey_' . $surveyid]['relevanceStatus'][$aQuotaMember['qid']];
            }
            // For each field : test if actual responses is in quota (and is relevant)
            foreach ($aQuotaFields as $sFieldName => $aValues) {
                $bInQuota = isset($_SESSION['survey_' . $surveyid][$sFieldName]) && in_array($_SESSION['survey_' . $surveyid][$sFieldName], $aValues);
                if ($bInQuota && $aQuotaRelevantFieldnames[$sFieldName]) {
                    $iMatchedAnswers++;
                }
                if (in_array($sFieldName, $aPostedFields)) {
                    $bPostedField = true;
                }
            }
            if ($iMatchedAnswers == count($aQuotaFields)) {
                switch ($aQuotaCompleted['action']) {
                    case '1':
                    default:
                        $aMatchedQuotas[] = $aQuotaCompleted;
                        break;
                    case '2':
                        if ($bPostedField) {
                            // Action 2 allow to correct last answers, then need to be posted
                            $aMatchedQuotas[] = $aQuotaCompleted;
                        }
                        break;
                }
            }
        }
    }
    if ($return) {
        return $aMatchedQuotas;
    }
    if (empty($aMatchedQuotas)) {
        return;
    }
    // Now we have all the information we need about the quotas and their status.
    // We need to construct the page and do all needed action
    $aSurveyInfo = getSurveyInfo($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
    $sTemplatePath = getTemplatePath($aSurveyInfo['templatedir']);
    $sClientToken = isset($_SESSION['survey_' . $surveyid]['token']) ? $_SESSION['survey_' . $surveyid]['token'] : "";
    // {TOKEN} is take by $redata ...
    // $redata for templatereplace
    $aDataReplacement = array('thissurvey' => $aSurveyInfo, 'clienttoken' => $sClientToken, 'token' => $sClientToken);
    // We take only the first matched quota, no need for each
    $aMatchedQuota = $aMatchedQuotas[0];
    // If a token is used then mark the token as completed, do it before event : this allow plugin to update token information
    $event = new PluginEvent('afterSurveyQuota');
    $event->set('surveyId', $surveyid);
    $event->set('responseId', $_SESSION['survey_' . $surveyid]['srid']);
    // We allways have a responseId
    $event->set('aMatchedQuotas', $aMatchedQuotas);
    // Give all the matched quota : the first is the active
    App()->getPluginManager()->dispatchEvent($event);
    $blocks = array();
    foreach ($event->getAllContent() as $blockData) {
        /* @var $blockData PluginEventContent */
//.........这里部分代码省略.........
开发者ID:elcharlygraf,项目名称:Encuesta-YiiFramework,代码行数:101,代码来源:frontend_helper.php

示例13: transformResponseValue

 /**
  * Performs a transformation of the response value.
  * Reload the survey to use own value
  *
  * @param string $sValue
  * @param string $fieldType
  * @param FormattingOptions $oOptions
  * @param string $sColumn The name of the column
  * @return string
  */
 protected function transformResponseValue($sValue, $fieldType, FormattingOptions $oOptions, $sColumn = null)
 {
     static $aColumnDone = array();
     // If $sValue is already done for column :; we can take it again, but a lot of memory ....
     if ($this->exportAnswerPosition == 'aseperatecodetext') {
         if (!array_key_exists($sColumn, $aColumnDone)) {
             $bExportAnswerCode = !self::sameTextAndCode($fieldType, $sColumn);
             $bExportAnswerText = self::sameTextAndCode($fieldType, $sColumn);
             $aColumnDone[$sColumn] = 1;
         } else {
             $bExportAnswerCode = false;
             $bExportAnswerText = true;
             unset($aColumnDone[$sColumn]);
         }
     } else {
         $bExportAnswerCode = $this->exportAnswerCode && !self::sameTextAndCode($fieldType, $sColumn);
         $bExportAnswerText = $this->exportAnswerText || self::sameTextAndCode($fieldType, $sColumn);
     }
     $sAnswerFull = "";
     $sAnswerText = "";
     $sAnswerCode = "";
     $oSurvey = $this->oSurvey;
     // We need survey to get answers ...
     // New event to allow another plugin to do something
     $oEvent = new PluginEvent('exportCompleteAnswersTransformResponseValue');
     $oEvent->set('sValue', $sValue);
     $oEvent->set('fieldType', $fieldType);
     $oEvent->set('oOptions', $oOptions);
     // Needed ?
     $oEvent->set('oSurvey', $oSurvey);
     App()->getPluginManager()->dispatchEvent($oEvent);
     $sAnswerFull = $oEvent->get('answerValue');
     // if $sAnswerFull is done by plugin, return it
     if (null !== $sAnswerFull) {
         return $sAnswerFull;
     }
     if ($bExportAnswerCode) {
         if (is_null($sValue)) {
             $sAnswerCode = $this->codeStringForNull;
         } else {
             $sAnswerCode = Writer::transformResponseValue($sValue, $fieldType, $oOptions, $sColumn);
         }
         if ($sValue != "" || $sValue === "" && $this->exportNullEmptyAnswerCode != "notempty" || is_null($sValue) && $this->exportNullEmptyAnswerCode == "always") {
             if ($this->exportAnswerPosition != 'aseperatecodetext') {
                 $sAnswerCode = $this->exportAnswerCodeBefore . $sAnswerCode . $this->exportAnswerCodeAfter;
             }
         }
     }
     if ($bExportAnswerText) {
         if (is_null($sValue)) {
             $sAnswerText = $this->textStringForNull;
         } else {
             $sAnswerText = Writer::transformResponseValue($oSurvey->getFullAnswer($sColumn, $sValue, $this->translator, $this->languageCode), $fieldType, $oOptions, $sColumn);
         }
         // Remove not needed N/A ....
         $aNaType = array('Y', 'G', 'M', 'P');
         if (in_array($fieldType, $aNaType) && $sAnswerText == "N/A") {
             $sAnswerText = "";
         }
     }
     if ($this->exportAnswerPosition == 'acodetext') {
         $sAnswerFull = $sAnswerCode . $sAnswerText;
     } elseif ($this->exportAnswerPosition == 'atextcode') {
         $sAnswerFull = $sAnswerText . $sAnswerCode;
     }
     return $sAnswerFull;
 }
开发者ID:BelgianHealthCareKnowledgeCentre,项目名称:LS-exportCompleteAnswers,代码行数:77,代码来源:exportCompleteAnswersWriter.php

示例14: hasPermission

 /**
  * Checks if a user has a certain permission
  *
  * @param $iEntityID integer The entity ID
  * @param $sEntityName string The entity name
  * @param $sPermission string Name of the permission
  * @param $sCRUD string The permission detail you want to check on: 'create','read','update','delete','import' or 'export'
  * @param $iUserID integer User ID - if not given the one of the current user is used
  * @return bool True if user has the permission
  */
 public function hasPermission($iEntityID, $sEntityName, $sPermission, $sCRUD = 'read', $iUserID = null)
 {
     // TODO: in entry script, if CConsoleApplication, set user as superadmin
     if (is_null($iUserID) && Yii::app() instanceof CConsoleApplication) {
         return true;
     }
     static $aPermissionStatic;
     /* Allow plugin to set own permission */
     // TODO: plugin should not be able to override the permission system (security issue),
     //      they should read permissions via the model
     //      and they should add row in permission table  (entity = plugin, etc)
     $oEvent = new PluginEvent('beforeHasPermission');
     $oEvent->set('iEntityID', $iEntityID);
     $oEvent->set('sEntityName', $sEntityName);
     $oEvent->set('sPermission', $sPermission);
     $oEvent->set('sCRUD', $sCRUD);
     $oEvent->set('iUserID', $iUserID);
     App()->getPluginManager()->dispatchEvent($oEvent);
     $pluginbPermission = $oEvent->get('bPermission');
     if (isset($pluginbPermission)) {
         return $pluginbPermission;
     }
     /* Always return true for CConsoleApplication (before or after plugin ? All other seems better after plugin) */
     // TODO: see above about entry script and superadmin
     if (is_null($iUserID) && Yii::app() instanceof CConsoleApplication) {
         return true;
     }
     /* Always return false for unknow sCRUD */
     // TODO: should not be necessary
     if (!in_array($sCRUD, array('create', 'read', 'update', 'delete', 'import', 'export'))) {
         return false;
     }
     $sCRUD = $sCRUD . '_p';
     /* Always return false for guests */
     // TODO: should not be necessary
     if (!$this->getUserId($iUserID)) {
         return false;
     } else {
         $iUserID = $this->getUserId($iUserID);
     }
     /* Always return true if you are the owner : this can be done in core plugin ? */
     // TODO: give the rights to owner adding line in permissions table, so it will return true with the normal way
     if ($iUserID == $this->getOwnerId($iEntityID, $sEntityName)) {
         return true;
     }
     /* Check if superadmin and static it */
     // TODO: give the rights to superadmin adding line in permissions table, so it will return true with the normal way
     if (!isset($aPermissionStatic[0]['global'][$iUserID]['superadmin']['read_p'])) {
         $aPermission = $this->findByAttributes(array("entity_id" => 0, 'entity' => 'global', "uid" => $iUserID, "permission" => 'superadmin'));
         $bPermission = is_null($aPermission) ? array() : $aPermission->attributes;
         if (!isset($bPermission['read_p']) || $bPermission['read_p'] == 0) {
             $bPermission = false;
         } else {
             $bPermission = true;
         }
         $aPermissionStatic[0]['global'][$iUserID]['superadmin']['read_p'] = $bPermission;
     }
     if ($aPermissionStatic[0]['global'][$iUserID]['superadmin']['read_p']) {
         return true;
     }
     /* Check in permission DB and static it */
     // TODO: that should be the only way to get the permission,
     // and it should be accessible from any object with relations :
     // $obj->permissions->read or $obj->permissions->write, etc.
     // relation :
     // 'permissions' => array(self::HAS_ONE, 'Permission', array(), 'condition'=> 'entity_id='.{ENTITYID}.' && uid='.Yii::app()->user->id.' && entity="{ENTITY}" && permission="{PERMISSIONS}"', 'together' => true ),
     if (!isset($aPermissionStatic[$iEntityID][$sEntityName][$iUserID][$sPermission][$sCRUD])) {
         $query = $this->findByAttributes(array("entity_id" => $iEntityID, "uid" => $iUserID, "entity" => $sEntityName, "permission" => $sPermission));
         $bPermission = is_null($query) ? array() : $query->attributes;
         if (!isset($bPermission[$sCRUD]) || $bPermission[$sCRUD] == 0) {
             $bPermission = false;
         } else {
             $bPermission = true;
         }
         $aPermissionStatic[$iEntityID][$sEntityName][$iUserID][$sPermission][$sCRUD] = $bPermission;
     }
     return $aPermissionStatic[$iEntityID][$sEntityName][$iUserID][$sPermission][$sCRUD];
 }
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:88,代码来源:Permission.php

示例15: action

 function action()
 {
     global $surveyid;
     global $thissurvey, $thisstep;
     global $clienttoken, $tokensexist, $token;
     // only attempt to change session lifetime if using a DB backend
     // with file based sessions, it's up to the admin to configure maxlifetime
     if (isset(Yii::app()->session->connectionID)) {
         @ini_set('session.gc_maxlifetime', Yii::app()->getConfig('iSessionExpirationTime'));
     }
     $this->_loadRequiredHelpersAndLibraries();
     $param = $this->_getParameters(func_get_args(), $_POST);
     $surveyid = $param['sid'];
     Yii::app()->setConfig('surveyID', $surveyid);
     $thisstep = $param['thisstep'];
     $move = getMove();
     Yii::app()->setConfig('move', $move);
     $clienttoken = trim($param['token']);
     $standardtemplaterootdir = Yii::app()->getConfig('standardtemplaterootdir');
     if (is_null($thissurvey) && !is_null($surveyid)) {
         $thissurvey = getSurveyInfo($surveyid);
     }
     // unused vars in this method (used in methods using compacted method vars)
     @($loadname = $param['loadname']);
     @($loadpass = $param['loadpass']);
     $sitename = Yii::app()->getConfig('sitename');
     if (isset($param['newtest']) && $param['newtest'] == "Y") {
         killSurveySession($surveyid);
     }
     $surveyExists = $surveyid && Survey::model()->findByPk($surveyid);
     $isSurveyActive = $surveyExists && Survey::model()->findByPk($surveyid)->active == "Y";
     // collect all data in this method to pass on later
     $redata = compact(array_keys(get_defined_vars()));
     $this->_loadLimesurveyLang($surveyid);
     if ($this->_isClientTokenDifferentFromSessionToken($clienttoken, $surveyid)) {
         $sReloadUrl = $this->getController()->createUrl("/survey/index/sid/{$surveyid}", array('token' => $clienttoken, 'lang' => App()->language, 'newtest' => 'Y'));
         $asMessage = array(gT('Token mismatch'), gT('The token you provided doesn\'t match the one in your session.'), "<a class='reloadlink newsurvey' href={$sReloadUrl}>" . gT("Click here to start the survey.") . "</a>");
         $this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
     }
     if ($this->_isSurveyFinished($surveyid) && ($thissurvey['alloweditaftercompletion'] != 'Y' || $thissurvey['tokenanswerspersistence'] != 'Y')) {
         $aReloadUrlParam = array('lang' => App()->language, 'newtest' => 'Y');
         if ($clienttoken) {
             $aReloadUrlParam['token'] = $clienttoken;
         }
         $sReloadUrl = $this->getController()->createUrl("/survey/index/sid/{$surveyid}", $aReloadUrlParam);
         $asMessage = array(gT('Previous session is set to be finished.'), gT('Your browser reports that it was used previously to answer this survey. We are resetting the session so that you can start from the beginning.'), "<a class='reloadlink newsurvey' href={$sReloadUrl}>" . gT("Click here to start the survey.") . "</a>");
         $this->_createNewUserSessionAndRedirect($surveyid, $redata, __LINE__, $asMessage);
     }
     $previewmode = false;
     if (isset($param['action']) && in_array($param['action'], array('previewgroup', 'previewquestion'))) {
         if (!$this->_canUserPreviewSurvey($surveyid)) {
             $asMessage = array(gT('Error'), gT("We are sorry but you don't have permissions to do this."));
             $this->_niceExit($redata, __LINE__, null, $asMessage);
         } else {
             if (intval($param['qid']) && $param['action'] == 'previewquestion') {
                 $previewmode = 'question';
             }
             if (intval($param['gid']) && $param['action'] == 'previewgroup') {
                 $previewmode = 'group';
             }
         }
     }
     Yii::app()->setConfig('previewmode', $previewmode);
     if ($this->_surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $isSurveyActive, $surveyExists)) {
         $bPreviewRight = $this->_userHasPreviewAccessSession($surveyid);
         if ($bPreviewRight === false) {
             $asMessage = array(gT("Error"), gT("We are sorry but you don't have permissions to do this."), sprintf(gT("Please contact %s ( %s ) for further assistance."), $thissurvey['adminname'], $thissurvey['adminemail']));
             $this->_niceExit($redata, __LINE__, null, $asMessage);
         }
     }
     // TODO can this be moved to the top?
     // (Used to be global, used in ExpressionManager, merged into amVars. If not filled in === '')
     // can this be added in the first computation of $redata?
     if (isset($_SESSION['survey_' . $surveyid]['srid'])) {
         $saved_id = $_SESSION['survey_' . $surveyid]['srid'];
     }
     // recompute $redata since $saved_id used to be a global
     $redata = compact(array_keys(get_defined_vars()));
     if ($this->_didSessionTimeOut($surveyid)) {
         // @TODO is this still required ?
         $asMessage = array(gT("Error"), gT("We are sorry but your session has expired."), gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection."), sprintf(gT("Please contact %s ( %s ) for further assistance."), $thissurvey['adminname'], $thissurvey['adminemail']));
         $this->_niceExit($redata, __LINE__, null, $asMessage);
     }
     // Set the language of the survey, either from POST, GET parameter of session var
     // Keep the old value, because SetSurveyLanguage update $_SESSION
     $sOldLang = isset($_SESSION['survey_' . $surveyid]['s_lang']) ? $_SESSION['survey_' . $surveyid]['s_lang'] : "";
     // Keep the old value, because SetSurveyLanguage update $_SESSION
     if (!empty($param['lang'])) {
         $sDisplayLanguage = $param['lang'];
         // $param take lang from returnGlobal and returnGlobal sanitize langagecode
     } elseif (isset($_SESSION['survey_' . $surveyid]['s_lang'])) {
         $sDisplayLanguage = $_SESSION['survey_' . $surveyid]['s_lang'];
     } elseif (Survey::model()->findByPk($surveyid)) {
         $sDisplayLanguage = Survey::model()->findByPk($surveyid)->language;
     } else {
         $sDisplayLanguage = Yii::app()->getConfig('defaultlang');
     }
     //CHECK FOR REQUIRED INFORMATION (sid)
     if ($surveyid && $surveyExists) {
         LimeExpressionManager::SetSurveyId($surveyid);
//.........这里部分代码省略.........
开发者ID:kochichi,项目名称:LimeSurvey,代码行数:101,代码来源:index.php


注:本文中的PluginEvent::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。