/**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $rcLib = $this->util->getReceptionCodeLibrary();
     $yesNo = $this->util->getTranslated()->getYesNo();
     $model = new \MUtil_Model_TableModel('gems__reception_codes');
     $model->copyKeys();
     // The user can edit the keys.
     $model->set('grc_id_reception_code', 'label', $this->_('Code'), 'size', '10');
     $model->set('grc_description', 'label', $this->_('Description'), 'size', '30');
     $model->set('grc_success', 'label', $this->_('Is success code'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('This reception code is a success code.'));
     $model->set('grc_active', 'label', $this->_('Active'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('Only active codes can be selected.'));
     if ($detailed) {
         $model->set('desc1', 'elementClass', 'Html', 'label', ' ', 'value', \MUtil_Html::create('h4', $this->_('Can be assigned to')));
     }
     $model->set('grc_for_respondents', 'label', $this->_('Respondents'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('This reception code can be assigned to a respondent.'));
     $model->set('grc_for_tracks', 'label', $this->_('Tracks'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('This reception code can be assigned to a track.'));
     $model->set('grc_for_surveys', 'label', $this->_('Tokens'), 'multiOptions', $rcLib->getSurveyApplicationValues(), 'description', $this->_('This reception code can be assigned to a token.'));
     if ($detailed) {
         $model->set('desc2', 'elementClass', 'Html', 'label', ' ', 'value', \MUtil_Html::create('h4', $this->_('Additional actions')));
     }
     $model->set('grc_redo_survey', 'label', $this->_('Redo survey'), 'multiOptions', $rcLib->getRedoValues(), 'description', $this->_('Redo a survey on this reception code.'));
     $model->set('grc_overwrite_answers', 'label', $this->_('Overwrite existing consents'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('Remove the consent from already answered surveys.'));
     if ($detailed) {
         $model->set('grc_id_reception_code', 'validator', $model->createUniqueValidator('grc_id_reception_code'));
         $model->set('grc_description', 'validator', $model->createUniqueValidator('grc_description'));
     }
     if ($this->project->multiLocale) {
         $model->set('grc_description', 'description', 'ENGLISH please! Use translation file to translate.');
     }
     \Gems_Model::setChangeFieldsByPrefix($model, 'grc');
     return $model;
 }
 /**
  * Construct a track model
  */
 public function __construct()
 {
     parent::__construct('gems__tracks');
     $this->addColumn("CASE WHEN gtr_track_class = 'SingleSurveyEngine' THEN 'deleted' ELSE '' END", 'row_class');
     \Gems_Model::setChangeFieldsByPrefix($this, 'gtr');
     $this->set('gtr_date_start', 'default', new \Zend_Date());
 }
 /**
  * Constructor
  *
  * @param array|mixed $styles
  */
 public function __construct($styles = array())
 {
     parent::__construct('organization', 'gems__organizations', 'gor');
     $this->_styles = $styles;
     $this->setDeleteValues('gor_active', 0, 'gor_add_respondents', 0);
     $this->addColumn("CASE WHEN gor_active = 1 THEN '' ELSE 'deleted' END", 'row_class');
     \Gems_Model::setChangeFieldsByPrefix($this, 'gor');
 }
 /**
  * Should handle execution of the task, taking as much (optional) parameters as needed
  *
  * The parameters should be optional and failing to provide them should be handled by
  * the task
  */
 public function execute($surveyId = null, $questionId = null, $order = null)
 {
     $batch = $this->getBatch();
     $survey = $this->loader->getTracker()->getSurvey($surveyId);
     // Now save the questions
     $answerModel = $survey->getAnswerModel('en');
     $questionModel = new \MUtil_Model_TableModel('gems__survey_questions');
     \Gems_Model::setChangeFieldsByPrefix($questionModel, 'gsq');
     $label = $answerModel->get($questionId, 'label');
     /*
             if ($label instanceof \MUtil_Html_HtmlInterface) {
                 $label = $label->render($this->view);
             }
             // */
     $question['gsq_id_survey'] = $surveyId;
     $question['gsq_name'] = $questionId;
     $question['gsq_name_parent'] = $answerModel->get($questionId, 'parent_question');
     $question['gsq_order'] = $order;
     $question['gsq_type'] = $answerModel->getWithDefault($questionId, 'type', \MUtil_Model::TYPE_STRING);
     $question['gsq_class'] = $answerModel->get($questionId, 'thClass');
     $question['gsq_group'] = $answerModel->get($questionId, 'group');
     $question['gsq_label'] = $label;
     $question['gsq_description'] = $answerModel->get($questionId, 'description');
     // \MUtil_Echo::track($question);
     try {
         $questionModel->save($question);
     } catch (\Exception $e) {
         $batch->addMessage(sprintf($this->_('Save failed for survey %s, question %s: %s'), $survey->getName(), $questionId, $e->getMessage()));
     }
     $batch->addToCounter('checkedQuestions');
     if ($questionModel->getChanged()) {
         $batch->addToCounter('changedQuestions');
     }
     $batch->setMessage('questionschanged', sprintf($this->_('%d of %d questions changed.'), $batch->getCounter('changedQuestions'), $batch->getCounter('checkedQuestions')));
     $options = $answerModel->get($questionId, 'multiOptions');
     if ($options) {
         $optionModel = new \MUtil_Model_TableModel('gems__survey_question_options');
         \Gems_Model::setChangeFieldsByPrefix($optionModel, 'gsqo');
         $option['gsqo_id_survey'] = $surveyId;
         $option['gsqo_name'] = $questionId;
         $i = 0;
         // \MUtil_Echo::track($options);
         foreach ($options as $key => $label) {
             $option['gsqo_order'] = $i;
             $option['gsqo_key'] = $key;
             $option['gsqo_label'] = $label;
             try {
                 $optionModel->save($option);
             } catch (\Exception $e) {
                 $batch->addMessage(sprintf($this->_('Save failed for survey %s, question %s, option "%s" => "%s": %s'), $survey->getName(), $questionId, $key, $label, $e->getMessage()));
             }
             $i++;
         }
         $batch->addToCounter('checkedOptions', count($options));
         $batch->addToCounter('changedOptions', $optionModel->getChanged());
         $batch->setMessage('optionschanged', sprintf($this->_('%d of %d options changed.'), $batch->getCounter('changedOptions'), $batch->getCounter('checkedOptions')));
     }
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel($detailed, $action)
 {
     $dbLookup = $this->util->getDbLookup();
     $dbTracks = $this->util->getTrackData();
     $translated = $this->util->getTranslated();
     $empty = $translated->getEmptyDropdownArray();
     $unselected = array('' => '');
     $model = new \MUtil_Model_TableModel('gems__comm_jobs');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gcj');
     $model->set('gcj_id_order', 'label', $this->_('Order'), 'description', $this->_('Execution order of the communication jobs, lower numbers are executed first.'));
     if ($detailed) {
         $model->set('gcj_id_order', 'validator', $model->createUniqueValidator('gcj_id_order'));
         if ($action == 'create') {
             // Set the default round order
             $newOrder = $this->db->fetchOne("SELECT MAX(gcj_id_order) FROM gems__comm_jobs");
             if ($newOrder) {
                 $model->set('gcj_id_order', 'default', $newOrder + 10);
             }
         }
     }
     $model->set('gcj_id_message', 'label', $this->_('Template'), 'multiOptions', $unselected + $dbLookup->getCommTemplates('token'));
     $model->set('gcj_id_user_as', 'label', $this->_('By staff member'), 'multiOptions', $unselected + $dbLookup->getActiveStaff(), 'default', $this->currentUser->getUserId(), 'description', $this->_('Used for logging and possibly from address.'));
     $model->set('gcj_active', 'label', $this->_('Active'), 'multiOptions', $translated->getYesNo(), 'elementClass', 'Checkbox', 'required', true, 'description', $this->_('Job is only run when active.'));
     $fromMethods = $unselected + $this->getBulkMailFromOptions();
     $model->set('gcj_from_method', 'label', $this->_('From address used'), 'multiOptions', $fromMethods);
     if ($detailed) {
         // Show other field only when last $fromMethod is select
         end($fromMethods);
         // Move array pointer to the end
         $lastKey = key($fromMethods);
         $switches = array($lastKey => array('gcj_from_fixed' => array('elementClass' => 'Text', 'label' => $this->_('From other'))));
         $model->addDependency(array('ValueSwitchDependency', $switches), 'gcj_from_method');
         $model->set('gcj_from_fixed', 'label', '', 'elementClass', 'Hidden');
     }
     $model->set('gcj_process_method', 'label', $this->_('Processing Method'), 'default', 'O', 'multiOptions', $translated->getBulkMailProcessOptions());
     $model->set('gcj_filter_mode', 'label', $this->_('Filter for'), 'multiOptions', $unselected + $this->getBulkMailFilterOptions());
     if ($detailed) {
         // Only show reminder fields when needed
         $switches = array('R' => array('gcj_filter_days_between' => array('elementClass' => 'Text', 'label' => $this->_('Days between reminders')), 'gcj_filter_max_reminders' => array('elementClass' => 'Text', 'label' => $this->_('Maximum reminders'))));
         $model->addDependency(array('ValueSwitchDependency', $switches), 'gcj_filter_mode');
         $model->set('gcj_filter_days_between', 'label', '', 'elementClass', 'Hidden', 'description', $this->_('1 day means the reminder is send the next day'), 'validators[]', 'Digits');
         $model->set('gcj_filter_max_reminders', 'label', '', 'elementClass', 'Hidden', 'description', $this->_('1 means only one reminder will be send'), 'validators[]', 'Digits');
     }
     // If you really want to see this information in the overview, uncomment for the shorter labels
     // $model->set('gcj_filter_days_between', 'label', $this->_('Interval'), 'validators[]', 'Digits');
     // $model->set('gcj_filter_max_reminders','label', $this->_('Max'), 'validators[]', 'Digits');
     $model->set('gcj_id_track', 'label', $this->_('Track'), 'multiOptions', $empty + $dbTracks->getAllTracks());
     $defaultRounds = $empty + $this->db->fetchPairs('SELECT gro_round_description, gro_round_description FROM gems__rounds WHERE gro_round_description IS NOT NULL AND gro_round_description != "" GROUP BY gro_round_description');
     $model->set('gcj_round_description', 'label', $this->_('Round'), 'multiOptions', $defaultRounds, 'variableSelect', array('source' => 'gcj_id_track', 'baseQuery' => $this->roundDescriptionQuery, 'ajax' => array('controller' => 'comm-job', 'action' => 'roundselect'), 'firstValue' => $empty, 'defaultValues' => $defaultRounds));
     $model->set('gcj_id_survey', 'label', $this->_('Survey'), 'multiOptions', $empty + $dbTracks->getAllSurveys(true));
     if ($detailed) {
         $model->set('gcj_id_organization', 'label', $this->_('Organization'), 'multiOptions', $empty + $dbLookup->getOrganizations());
     }
     return $model;
 }
 /**
  *
  * @param string $modelName Hopefully unique model name
  * @param string $modelField The name of the field used to store the sub model
  */
 public function __construct($modelName = 'fields_maintenance', $modelField = 'sub')
 {
     parent::__construct($modelName, $modelField);
     $modelF = new \MUtil_Model_TableModel('gems__respondent2track2field');
     \Gems_Model::setChangeFieldsByPrefix($modelF, 'gr2t2f');
     $this->addUnionModel($modelF, null, FieldMaintenanceModel::FIELDS_NAME);
     $modelA = new \MUtil_Model_TableModel('gems__respondent2track2appointment');
     \Gems_Model::setChangeFieldsByPrefix($modelA, 'gr2t2a');
     $mapBase = $modelA->getItemsOrdered();
     $map = array_combine($mapBase, str_replace('gr2t2a_', 'gr2t2f_', $mapBase));
     $map['gr2t2a_id_app_field'] = 'gr2t2f_id_field';
     $map['gr2t2a_id_appointment'] = 'gr2t2f_value';
     $this->addUnionModel($modelA, $map, FieldMaintenanceModel::APPOINTMENTS_NAME);
 }
    /**
     * Creates a model for getModel(). Called only for each new $action.
     *
     * The parameters allow you to easily adapt the model to the current action. The $detailed
     * parameter was added, because the most common use of action is a split between detailed
     * and summarized actions.
     *
     * @param boolean $detailed True when the current action is not in $summarizedActions.
     * @param string $action The current action.
     * @return \MUtil_Model_ModelAbstract
     */
    protected function createModel($detailed, $action)
    {
        $translated = $this->util->getTranslated();
        $model = new \MUtil_Model_TableModel('gems__agenda_activities');
        \Gems_Model::setChangeFieldsByPrefix($model, 'gaa');
        $model->setDeleteValues('gaa_active', 0);
        $model->set('gaa_name', 'label', $this->_('Activity'), 'description', $this->_('An activity is a high level description about an appointment:
e.g. consult, check-up, diet, operation, physiotherapy or other.'), 'required', true);
        $model->setIfExists('gaa_id_organization', 'label', $this->_('Organization'), 'description', $this->_('Optional, an import match with an organization has priority over those without.'), 'multiOptions', $translated->getEmptyDropdownArray() + $this->util->getDbLookup()->getOrganizations());
        $model->setIfExists('gaa_name_for_resp', 'label', $this->_('Respondent explanation'), 'description', $this->_('Alternative description to use with respondents.'));
        $model->setIfExists('gaa_match_to', 'label', $this->_('Import matches'), 'description', $this->_("Split multiple import matches using '|'."));
        $model->setIfExists('gaa_code', 'label', $this->_('Activity code'), 'size', 10, 'description', $this->_('Optional code name to link the activity to program code.'));
        $model->setIfExists('gaa_active', 'label', $this->_('Active'), 'description', $this->_('Inactive means assignable only through automatich processes.'), 'elementClass', 'Checkbox', 'multiOptions', $translated->getYesNo());
        $model->setIfExists('gaa_filter', 'label', $this->_('Filter'), 'description', $this->_('When checked appointments with these activities are not imported.'), 'elementClass', 'Checkbox', 'multiOptions', $translated->getYesNo());
        $model->addColumn("CASE WHEN gaa_active = 1 THEN '' ELSE 'deleted' END", 'row_class');
        return $model;
    }
    /**
     * Creates a model for getModel(). Called only for each new $action.
     *
     * The parameters allow you to easily adapt the model to the current action. The $detailed
     * parameter was added, because the most common use of action is a split between detailed
     * and summarized actions.
     *
     * @param boolean $detailed True when the current action is not in $summarizedActions.
     * @param string $action The current action.
     * @return \MUtil_Model_ModelAbstract
     */
    protected function createModel($detailed, $action)
    {
        $translated = $this->util->getTranslated();
        $model = new \MUtil_Model_TableModel('gems__agenda_procedures');
        \Gems_Model::setChangeFieldsByPrefix($model, 'gapr');
        $model->setDeleteValues('gapr_active', 0);
        $model->set('gapr_name', 'label', $this->_('Activity'), 'description', $this->_('A procedure describes an appointments effects on a respondent:
e.g. an excercise, an explanantion, a massage, mindfullness, a (specific) operation, etc...'), 'required', true);
        $model->setIfExists('gapr_id_organization', 'label', $this->_('Organization'), 'description', $this->_('Optional, an import match with an organization has priority over those without.'), 'multiOptions', $translated->getEmptyDropdownArray() + $this->util->getDbLookup()->getOrganizations());
        $model->setIfExists('gapr_name_for_resp', 'label', $this->_('Respondent explanation'), 'description', $this->_('Alternative description to use with respondents.'));
        $model->setIfExists('gapr_match_to', 'label', $this->_('Import matches'), 'description', $this->_("Split multiple import matches using '|'."));
        $model->setIfExists('gapr_code', 'label', $this->_('Procedure code'), 'size', 10, 'description', $this->_('Optional code name to link the procedure to program code.'));
        $model->setIfExists('gapr_active', 'label', $this->_('Active'), 'description', $this->_('Inactive means assignable only through automatich processes.'), 'elementClass', 'Checkbox', 'multiOptions', $translated->getYesNo());
        $model->setIfExists('gapr_filter', 'label', $this->_('Filter'), 'description', $this->_('When checked appointments with these procedures are not imported.'), 'elementClass', 'Checkbox', 'multiOptions', $translated->getYesNo());
        $model->addColumn("CASE WHEN gapr_active = 1 THEN '' ELSE 'deleted' END", 'row_class');
        return $model;
    }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel($detailed, $action)
 {
     $dblookup = $this->util->getDbLookup();
     $translated = $this->util->getTranslated();
     $model = new \MUtil_Model_TableModel('gems__agenda_staff');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gas');
     $model->setDeleteValues('gas_active', 0);
     $model->set('gas_name', 'label', $this->_('Name'), 'required', true);
     $model->set('gas_function', 'label', $this->_('Function'));
     $model->setIfExists('gas_id_organization', 'label', $this->_('Organization'), 'multiOptions', $dblookup->getOrganizations(), 'required', true);
     $model->setIfExists('gas_id_user', 'label', $this->_('GemsTracker user'), 'description', $this->_('Optional: link this health care provider to a GemsTracker Staff user.'), 'multiOptions', $translated->getEmptyDropdownArray() + $dblookup->getStaff());
     $model->setIfExists('gas_match_to', 'label', $this->_('Import matches'), 'description', $this->_("Split multiple import matches using '|'."));
     $model->setIfExists('gas_active', 'label', $this->_('Active'), 'description', $this->_('Inactive means assignable only through automatich processes.'), 'elementClass', 'Checkbox', 'multiOptions', $translated->getYesNo());
     $model->setIfExists('gas_filter', 'label', $this->_('Filter'), 'description', $this->_('When checked appointments with this staff member are not imported.'), 'elementClass', 'Checkbox', 'multiOptions', $translated->getYesNo());
     $model->addColumn("CASE WHEN gas_active = 1 THEN '' ELSE 'deleted' END", 'row_class');
     return $model;
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $model = new \MUtil_Model_TableModel('gems__groups');
     // Add id for excel export
     if ($action == 'export') {
         $model->set('ggp_id_group', 'label', 'id');
     }
     $model->set('ggp_name', 'label', $this->_('Name'), 'size', 15, 'minlength', 4, 'validator', $model->createUniqueValidator('ggp_name'));
     $model->set('ggp_description', 'label', $this->_('Description'), 'size', 40);
     $model->set('ggp_role', 'label', $this->_('Role'), 'multiOptions', $this->util->getDbLookup()->getRoles());
     $yesNo = $this->util->getTranslated()->getYesNo();
     $model->set('ggp_group_active', 'label', $this->_('Active'), 'multiOptions', $yesNo, 'elementClass', 'Checkbox');
     $model->set('ggp_staff_members', 'label', $this->_('Staff'), 'multiOptions', $yesNo, 'elementClass', 'Checkbox');
     $model->set('ggp_respondent_members', 'label', $this->_('Respondents'), 'multiOptions', $yesNo, 'elementClass', 'Checkbox');
     $model->set('ggp_allowed_ip_ranges', 'label', $this->_('Allowed IP Ranges'), 'description', $this->_('Separate with | example: 10.0.0.0-10.0.0.255 (subnet masks are not supported)'), 'size', 50, 'validator', new \Gems_Validate_IPRanges(), 'maxlength', 500);
     \Gems_Model::setChangeFieldsByPrefix($model, 'ggp');
     return $model;
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * $return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $model = new \MUtil_Model_TableModel('gems__mail_servers');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gms');
     // Key can be changed by users
     $model->copyKeys();
     $model->set('gms_from', 'label', $this->_('From address [part]'), 'size', 30, 'description', $this->_("E.g.: '%', '%.org' or '*****@*****.**' or '*****@*****.**'."));
     $model->set('gms_server', 'label', $this->_('Server'), 'size', 30);
     $model->set('gms_ssl', 'label', $this->_('Encryption'), 'required', false, 'multiOptions', array(\Gems_Mail::MAIL_NO_ENCRYPT => $this->_('None'), \Gems_Mail::MAIL_SSL => $this->_('SSL'), \Gems_Mail::MAIL_TLS => $this->_('TLS')));
     $model->set('gms_port', 'label', $this->_('Port'), 'required', true, 'description', $this->_('Normal values: 25 for TLS and no encryption, 465 for SSL'), 'validator', 'Digits');
     $model->set('gms_user', 'label', $this->_('User ID'), 'size', 20);
     if ($detailed) {
         $model->set('gms_password', 'label', $this->_('Password'), 'elementClass', 'Password', 'repeatLabel', $this->_('Repeat password'), 'description', $this->_('Enter only when changing'));
         $type = new \Gems_Model_Type_EncryptedField($this->project, true);
         $type->apply($model, 'gms_password', 'gms_encryption');
     }
     return $model;
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $model = new \MUtil_Model_TableModel('gems__consents');
     $model->copyKeys();
     // The user can edit the keys.
     $model->set('gco_description', 'label', $this->_('Description'), 'size', '10');
     $model->set('gco_order', 'label', $this->_('Order'), 'size', '10', 'description', $this->_('Determines order of presentation in interface.'), 'validator', 'Digits');
     $model->set('gco_code', 'label', $this->_('Consent code'), 'multiOptions', $this->util->getConsentTypes(), 'description', $this->_('Internal code, not visible to users, copied with the token information to the source.'));
     if ($detailed) {
         $model->set('gco_description', 'validator', $model->createUniqueValidator('gco_description'));
         $model->set('gco_order', 'validator', $model->createUniqueValidator('gco_order'));
     }
     if ($this->project->multiLocale) {
         $model->set('gco_description', 'description', 'ENGLISH please! Use translation file to translate.');
     }
     \Gems_Model::setChangeFieldsByPrefix($model, 'gco');
     return $model;
 }
 /**
  * Overrule this function for any activities you want to take place
  * after the form has successfully been validated, but before any
  * buttons are processed.
  *
  * @param int $step The current step
  */
 protected function afterFormValidationFor($step)
 {
     if (3 == $step) {
         $import = $this->loadImportData();
         $model = $this->getModel();
         $saves = array();
         foreach ($model->getCol('exportCode') as $name => $exportCode) {
             if (isset($this->formData[$name]) && $this->formData[$name]) {
                 $saves[] = array('gsu_id_survey' => $this->formData[$name], 'gsu_export_code' => $exportCode);
                 $import['surveyCodes'][$exportCode] = $this->formData[$name];
             }
         }
         if ($saves) {
             $sModel = new \MUtil_Model_TableModel('gems__surveys');
             \Gems_Model::setChangeFieldsByPrefix($sModel, 'gus', $this->currentUser->getUserId());
             $sModel->saveAll($saves);
             $count = $sModel->getChanged();
             if ($count == 0) {
                 $this->addMessage($this->_('No export code changed'));
             } else {
                 $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('surveys'));
                 $this->addMessage(sprintf($this->plural('%d export code changed', '%d export codes changed', $count), $count));
             }
         }
     }
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel($detailed, $action)
 {
     $dbLookup = $this->util->getDbLookup();
     $dbTracks = $this->util->getTrackData();
     $translated = $this->util->getTranslated();
     $empty = $translated->getEmptyDropdownArray();
     $unselected = array('' => '');
     $model = new \MUtil_Model_TableModel('gems__comm_jobs');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gcj');
     $model->set('gcj_id_message', 'label', $this->_('Template'), 'multiOptions', $unselected + $dbLookup->getCommTemplates('token'));
     $model->set('gcj_id_user_as', 'label', $this->_('By staff member'), 'multiOptions', $unselected + $dbLookup->getActiveStaff(), 'default', $this->currentUser->getUserId(), 'description', $this->_('Used for logging and possibly from address.'));
     $model->set('gcj_active', 'label', $this->_('Active'), 'multiOptions', $translated->getYesNo(), 'elementClass', 'Checkbox', 'required', true, 'description', $this->_('Job is only run when active.'));
     $fromMethods = $unselected + $this->getBulkMailFromOptions();
     $model->set('gcj_from_method', 'label', $this->_('From address used'), 'multiOptions', $fromMethods);
     if ($detailed) {
         $model->set('gcj_from_fixed', 'label', $this->_('From other'), 'description', sprintf($this->_("Only when '%s' is '%s'."), $model->get('gcj_from_method', 'label'), end($fromMethods)));
     }
     $model->set('gcj_process_method', 'label', $this->_('Processing Method'), 'default', 'O', 'multiOptions', $translated->getBulkMailProcessOptions());
     $model->set('gcj_filter_mode', 'label', $this->_('Filter for'), 'multiOptions', $unselected + $this->getBulkMailFilterOptions());
     // If you really want to see this information in the overview, uncomment for the shorter labels
     // $model->set('gcj_filter_days_between', 'label', $this->_('Interval'), 'validators[]', 'Digits');
     // $model->set('gcj_filter_max_reminders','label', $this->_('Max'), 'validators[]', 'Digits');
     $model->set('gcj_id_track', 'label', $this->_('Track'), 'multiOptions', $empty + $dbTracks->getAllTracks());
     $defaultRounds = $empty + $this->db->fetchPairs('SELECT gro_round_description, gro_round_description FROM gems__rounds WHERE gro_round_description IS NOT NULL AND gro_round_description != "" GROUP BY gro_round_description');
     $model->set('gcj_round_description', 'label', $this->_('Round'), 'multiOptions', $defaultRounds, 'variableSelect', array('source' => 'gcj_id_track', 'baseQuery' => $this->roundDescriptionQuery, 'ajax' => array('controller' => 'comm-job', 'action' => 'roundselect'), 'firstValue' => $empty, 'defaultValues' => $defaultRounds));
     $model->set('gcj_id_survey', 'label', $this->_('Survey'), 'multiOptions', $empty + $dbTracks->getAllSurveys());
     if ($detailed) {
         $model->set('gcj_filter_days_between', 'label', $this->_('Days between reminders'), 'description', $this->_('1 day means the reminder is send the next day'), 'validators[]', 'Digits');
         $model->set('gcj_filter_max_reminders', 'label', $this->_('Maximum reminders'), 'description', $this->_('1 means only one reminder will be send'), 'validators[]', 'Digits');
         $model->set('gcj_id_organization', 'label', $this->_('Organization'), 'multiOptions', $empty + $dbLookup->getOrganizations());
     }
     return $model;
 }
 /**
  *
  * @param string $modelName Hopefully unique model name
  * @param string $modelField The name of the field used to store the sub model
  */
 public function __construct($modelName = 'fields_maintenance', $modelField = 'sub')
 {
     parent::__construct($modelName, $modelField);
     $model = new \MUtil_Model_TableModel('gems__track_fields');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gtf');
     $this->addUnionModel($model, null, self::FIELDS_NAME);
     $model = new \MUtil_Model_TableModel('gems__track_appointments');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gtap');
     $map = $model->getItemsOrdered();
     $map = array_combine($map, str_replace('gtap_', 'gtf_', $map));
     $map['gtap_id_app_field'] = 'gtf_id_field';
     $this->addUnionModel($model, $map, self::APPOINTMENTS_NAME);
     $model->addColumn(new \Zend_Db_Expr("'appointment'"), 'gtf_field_type');
     $model->addColumn(new \Zend_Db_Expr("NULL"), 'gtf_field_values');
     $model->addColumn(new \Zend_Db_Expr("NULL"), 'gtf_calculate_using');
     $this->setKeys(array(\Gems_Model::FIELD_ID => 'gtf_id_field', \MUtil_Model::REQUEST_ID => 'gtf_id_track'));
     $this->setClearableKeys(array(\Gems_Model::FIELD_ID => 'gtf_id_field'));
     $this->setSort(array('gtf_id_order' => SORT_ASC));
 }
 /**
  * Return a password reset key
  *
  * @param \Gems_User_User $user The user to create a key for.
  * @return string
  */
 public function getPasswordResetKey(\Gems_User_User $user)
 {
     $model = new \MUtil_Model_TableModel('gems__staff');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gsf', $user->getUserId());
     $data['gsf_id_user'] = $user->getUserId();
     $row = $model->loadFirst($data + array('DATE_ADD(gsf_reset_req, INTERVAL ' . $this->hoursResetKeyIsValid . ' HOUR) >= CURRENT_TIMESTAMP'));
     if ($row && $row['gup_reset_key']) {
         // Keep using the key.
         $data['gsf_reset_key'] = $row['gsf_reset_key'];
     } else {
         $data['gsf_reset_key'] = $this->hashPassword(time() . $user->getEmailAddress());
     }
     $data['gsf_reset_req'] = new \MUtil_Db_Expr_CurrentTimestamp();
     // Loop for case when hash is not unique
     while (true) {
         try {
             $model->save($data);
             // Old staff keys can by recognized because they start with 'os'
             return 'os' . $data['gsf_reset_key'];
         } catch (\Zend_Db_Exception $zde) {
             $data['gsf_reset_key'] = $this->hashPassword(time() . $user->getEmailAddress());
         }
     }
 }
 /**
  * Set the password, if allowed for this user type.
  *
  * @param \Gems_User_User $user The user whose password to change
  * @param string $password
  * @return \Gems_User_UserDefinitionInterface (continuation pattern)
  */
 public function setPassword(\Gems_User_User $user, $password)
 {
     $data['gup_id_user'] = $user->getUserLoginId();
     $data['gup_reset_key'] = null;
     $data['gup_reset_requested'] = null;
     $data['gup_reset_required'] = 0;
     if (null === $password) {
         // Passwords may be emptied.
         $data['gup_password'] = null;
     } else {
         $data['gup_password'] = $this->hashPassword($password);
     }
     $data['gup_last_pwd_change'] = new \Zend_Db_Expr('CURRENT_TIMESTAMP');
     $model = new \MUtil_Model_TableModel('gems__user_passwords');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId());
     $model->save($data);
     return $this;
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $model = new \MUtil_Model_TableModel('gems__roles');
     $model->set('grl_name', 'label', $this->_('Name'), 'size', 15, 'minlength', 4);
     $model->set('grl_description', 'label', $this->_('Description'), 'size', 40);
     $model->set('grl_parents', 'label', $this->_('Parents'));
     $tpa = new \MUtil_Model_Type_ConcatenatedRow(',', ', ');
     $tpa->apply($model, 'grl_parents');
     $model->setOnLoad('grl_parents', array(\Gems_Roles::getInstance(), 'translateToRoleNames'));
     $model->set('grl_privileges', 'label', $this->_('Privileges'));
     $tpr = new \MUtil_Model_Type_ConcatenatedRow(',', '<br/>');
     $tpr->apply($model, 'grl_privileges');
     if ($detailed) {
         $model->set('grl_name', 'validators[unique]', $model->createUniqueValidator('grl_name'), 'validators[nomaster]', new \MUtil_Validate_IsNot('master', $this->_('The name "master" is reserved')));
         $model->set('grl_privileges', 'formatFunction', array($this, 'formatPrivileges'));
         if ('show' === $action) {
             $model->addColumn('grl_parents', 'inherited');
             $tpa->apply($model, 'inherited');
             $model->set('inherited', 'label', $this->_('Inherited privileges'), 'formatFunction', array($this, 'formatInherited'));
             $model->setOnLoad('inherited', array(\Gems_Roles::getInstance(), 'translateToRoleNames'));
             // Concatenated field, we can not use onload so handle transaltion to rolenames in the formatFunction
             $model->addColumn("CONCAT(COALESCE(grl_parents, ''), '\t', COALESCE(grl_privileges, ''))", 'not_allowed');
             $model->set('not_allowed', 'label', $this->_('Not allowed'), 'formatFunction', array($this, 'formatNotAllowed'));
         }
     } else {
         $model->set('grl_privileges', 'formatFunction', array($this, 'formatLongLine'));
     }
     \Gems_Model::setChangeFieldsByPrefix($model, 'grl');
     return $model;
 }
Esempio n. 19
0
 /**
  * Find a procedure code for the name and organization.
  *
  * @param string $name The name to match against
  * @param int $organizationId Organization id
  * @param boolean $create Create a match when it does not exist
  * @return int or null
  */
 public function matchProcedure($name, $organizationId, $create = true)
 {
     $cacheId = __CLASS__ . '_' . __FUNCTION__;
     $matches = $this->cache->load($cacheId);
     if (!$matches) {
         $matches = array();
         $select = $this->db->select();
         $select->from('gems__agenda_procedures', array('gapr_id_procedure', 'gapr_match_to', 'gapr_id_organization', 'gapr_filter'));
         $result = $this->db->fetchAll($select);
         foreach ($result as $row) {
             if (null === $row['gapr_id_organization']) {
                 $key = 'null';
             } else {
                 $key = $row['gapr_id_organization'];
             }
             foreach (explode('|', $row['gapr_match_to']) as $match) {
                 $matches[$match][$key] = $row['gapr_filter'] ? false : $row['gapr_id_procedure'];
             }
         }
         $this->cache->save($matches, $cacheId, array('procedures'));
     }
     if (isset($matches[$name])) {
         if (isset($matches[$name][$organizationId])) {
             return $matches[$name][$organizationId];
         }
         if (isset($matches[$name]['null'])) {
             return $matches[$name]['null'];
         }
     }
     if (!$create) {
         return null;
     }
     $model = new \MUtil_Model_TableModel('gems__agenda_procedures');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gapr');
     $values = array('gapr_name' => $name, 'gapr_id_organization' => $organizationId, 'gapr_match_to' => $name, 'gapr_active' => 1, 'gapr_filter' => 0);
     $result = $model->save($values);
     $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('procedure', 'procedures'));
     return $result['gapr_id_procedure'];
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $tracker = $this->loader->getTracker();
     $model = new \MUtil_Model_TableModel('gems__sources');
     $model->set('gso_source_name', 'label', $this->_('Name'), 'description', $this->_('E.g. the name of the project - for single source projects.'), 'size', 15, 'minlength', 4, 'validator', $model->createUniqueValidator('gso_source_name'));
     $model->set('gso_ls_url', 'label', $this->_('Source Url'), 'default', 'http://', 'description', $this->_('For creating token-survey url.'), 'size', 50, 'validators[unique]', $model->createUniqueValidator('gso_ls_url'), 'validators[url]', new \MUtil_Validate_Url());
     $sourceClasses = $tracker->getSourceClasses();
     end($sourceClasses);
     $model->set('gso_ls_class', 'label', $this->_('Adaptor class'), 'default', key($sourceClasses), 'multiOptions', $sourceClasses);
     $model->set('gso_ls_adapter', 'label', $this->_('Database Server'), 'default', substr(get_class($this->db), strlen('Zend_Db_Adapter_')), 'description', $this->_('The database server used by the source.'), 'multiOptions', $tracker->getSourceDatabaseClasses());
     $model->set('gso_ls_table_prefix', 'label', $this->_('Table prefix'), 'default', 'ls__', 'description', $this->_('Do not forget the underscores.'), 'size', 15);
     if ($detailed) {
         $in_gems = $this->_('Leave empty for the Gems database.');
         $model->set('gso_ls_dbhost', 'label', $this->_('Database host'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_database', 'label', $this->_('Database'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_username', 'label', $this->_('Database Username'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_password', 'label', $this->_('Database Password'), 'elementClass', 'Password', 'repeatLabel', $this->_('Repeat password'), 'required', false, 'size', 15);
         if ('create' == $action) {
             $model->set('gso_ls_password', 'description', $in_gems, 'renderPassword', true);
         } else {
             $model->set('gso_ls_password', 'description', $this->_('Enter only when changing'), 'renderPassword', false);
         }
         $type = new \Gems_Model_Type_EncryptedField($this->project, true);
         $type->apply($model, 'gso_ls_password', 'gso_encryption');
         $model->set('gso_ls_charset', 'label', $this->_('Charset'), 'description', $in_gems, 'size', 15);
         $model->set('gso_active', 'label', $this->_('Active'), 'default', 0, 'multiOptions', $this->util->getTranslated()->getYesNo());
     }
     $model->set('gso_status', 'label', $this->_('Status'), 'default', 'Not checked', 'elementClass', 'Exhibitor');
     $model->set('gso_last_synch', 'label', $this->_('Last synchronisation'), 'elementClass', 'Exhibitor');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gso');
     return $model;
 }
 /**
  * Overrule this function for any activities you want to take place
  * after the form has successfully been validated, but before any
  * buttons are processed.
  *
  * @param int $step The current step
  */
 protected function afterFormValidationFor($step)
 {
     parent::afterFormValidationFor($step);
     if ($this->trackEngine) {
         if (4 == $step) {
             $import = $this->loadImportData();
             $model = $this->getModel();
             $saves = array();
             $import['deactivateRounds'] = array();
             foreach ($model->getCol('roundId') as $name => $roundId) {
                 $round = $this->trackEngine->getRound($roundId);
                 if (isset($this->formData[$name]) && $this->formData[$name] && $round instanceof Round) {
                     switch ($this->formData[$name]) {
                         case self::ROUND_DEACTIVATE:
                             $import['deactivateRounds'][$roundId] = $round->getFullDescription();
                             break;
                         case self::ROUND_LEAVE:
                             if (isset($import['roundOrderToLine'][$round->getRoundOrder()])) {
                                 $lineNr = $import['roundOrderToLine'][$round->getRoundOrder()];
                                 unset($import['rounds'][$lineNr]);
                             }
                             $import['roundOrders'][$round->getRoundOrder()] = $roundId;
                             break;
                         default:
                             if (isset($import['roundOrderToLine'][$this->formData[$name]])) {
                                 $lineNr = $import['roundOrderToLine'][$this->formData[$name]];
                                 $import['rounds'][$lineNr]['gro_id_round'] = $roundId;
                             }
                             $import['roundOrders'][$this->formData[$name]] = $roundId;
                             break;
                     }
                 }
             }
         }
     } elseif (3 == $step) {
         $import = $this->loadImportData();
         $model = $this->getModel();
         $saves = array();
         foreach ($model->getCol('exportCode') as $name => $exportCode) {
             if (isset($this->formData[$name]) && $this->formData[$name]) {
                 $saves[] = array('gsu_id_survey' => $this->formData[$name], 'gsu_export_code' => $exportCode);
                 $import['surveyCodes'][$exportCode] = $this->formData[$name];
             }
         }
         if ($saves) {
             $sModel = new \MUtil_Model_TableModel('gems__surveys');
             \Gems_Model::setChangeFieldsByPrefix($sModel, 'gus', $this->currentUser->getUserId());
             $sModel->saveAll($saves);
             $count = $sModel->getChanged();
             if ($count == 0) {
                 $this->addMessage($this->_('No export code changed'));
             } else {
                 $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('surveys'));
                 $this->addMessage(sprintf($this->plural('%d export code changed', '%d export codes changed', $count), $count));
             }
         }
     }
 }
 /**
  *
  * @param string $table_name  Does not test for existence
  * @param string $fieldPrefix Prefix to use for change fields (date/userid), if $saveable empty sets it to true
  * @param mixed  $saveable    Will changes to this table be saved, true or a combination of SAVE_MODE constants
  * @return \Gems_Model_JoinModel
  */
 public function setTableSaveable($table_name, $fieldPrefix = null, $saveable = null)
 {
     parent::setTableSaveable($table_name, $this->_checkSaveable($saveable, $fieldPrefix));
     if ($fieldPrefix) {
         \Gems_Model::setChangeFieldsByPrefix($this, $fieldPrefix);
     }
     return $this;
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel($detailed, $action)
 {
     $model = new \MUtil_Model_TableModel('gems__locations');
     $yesNo = $this->util->getTranslated()->getYesNo();
     \Gems_Model::setChangeFieldsByPrefix($model, 'glo');
     $model->setDeleteValues('glo_active', 0);
     $model->set('glo_name', 'label', $this->_('Location'), 'required', true);
     $model->set('glo_organizations', 'label', $this->_('Organizations'), 'description', $this->_('Checked organizations see this organizations respondents.'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'noSort', true);
     $tp = new \MUtil_Model_Type_ConcatenatedRow(':', ', ');
     $tp->apply($model, 'glo_organizations');
     $model->setIfExists('glo_match_to', 'label', $this->_('Import matches'), 'description', $this->_("Split multiple import matches using '|'."));
     $model->setIfExists('glo_code', 'label', $this->_('Location code'), 'size', 10, 'description', $this->_('Optional code name to link the location to program code.'));
     $model->setIfExists('glo_url', 'label', $this->_('Location url'), 'description', $this->_('Complete url for location: http://www.domain.etc'), 'validator', 'Url');
     $model->setIfExists('glo_url_route', 'label', $this->_('Location route url'), 'description', $this->_('Complete url for route to location: http://www.domain.etc'), 'validator', 'Url');
     $model->setIfExists('glo_address_1', 'label', $this->_('Street'));
     $model->setIfExists('glo_address_2', 'label', ' ');
     $model->setIfExists('glo_zipcode', 'label', $this->_('Zipcode'), 'size', 7, 'description', $this->_('E.g.: 0000 AA'), 'filter', new \Gems_Filter_DutchZipcode());
     $model->setIfExists('glo_city', 'label', $this->_('City'));
     $model->setIfExists('glo_region', 'label', $this->_('Region'));
     $model->setIfExists('glo_iso_country', 'label', $this->_('Country'), 'multiOptions', $this->util->getLocalized()->getCountries());
     $model->setIfExists('glo_phone_1', 'label', $this->_('Phone'));
     $model->setIfExists('glo_phone_2', 'label', $this->_('Phone 2'));
     $model->setIfExists('glo_phone_3', 'label', $this->_('Phone 3'));
     $model->setIfExists('glo_phone_4', 'label', $this->_('Phone 4'));
     $model->setIfExists('glo_active', 'label', $this->_('Active'), 'description', $this->_('Inactive means assignable only through automatich processes.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo);
     $model->setIfExists('glo_filter', 'label', $this->_('Filter'), 'description', $this->_('When checked appointments with these locations are not imported.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo);
     $model->addColumn("CASE WHEN glo_active = 1 THEN '' ELSE 'deleted' END", 'row_class');
     return $model;
 }