/** * Define the form's contents * */ public function definition() { // Want to know if there are any meta enrol plugin // instances in this course. $metacourse = $this->_customdata['data']->metacourse; $this->_form->addElement('hidden', local_userenrols_plugin::FORMID_METACOURSE, $metacourse ? '1' : '0'); $this->_form->setType(local_userenrols_plugin::FORMID_METACOURSE, PARAM_INT); if ($metacourse) { $this->_form->addElement('warning', null, null, get_string('INF_METACOURSE_WARN', local_userenrols_plugin::PLUGIN_NAME)); } $this->_form->addElement('header', 'identity', get_string('LBL_IDENTITY_OPTIONS', local_userenrols_plugin::PLUGIN_NAME)); // The userid field name drop down list $this->_form->addElement('select', local_userenrols_plugin::FORMID_USER_ID_FIELD, get_string('LBL_USER_ID_FIELD', local_userenrols_plugin::PLUGIN_NAME), $this->_customdata['data']->user_id_field_options); $this->_form->setDefault(local_userenrols_plugin::FORMID_USER_ID_FIELD, local_userenrols_plugin::DEFAULT_USER_ID_FIELD); $this->_form->addHelpButton(local_userenrols_plugin::FORMID_USER_ID_FIELD, 'LBL_USER_ID_FIELD', local_userenrols_plugin::PLUGIN_NAME); $this->_form->addElement('header', 'identity', get_string('LBL_ENROLL_OPTIONS', local_userenrols_plugin::PLUGIN_NAME)); // The role id drop down list. The get_assignable_roles returns an assoc. array // with integer keys (role id) and role name values, so it looks like a sparse // array. The php array functions tend to reorder the keys to remove the perceived // gaps, so have to merge manually with the 0 option. $roles = HTML_QuickForm::arrayMerge(array(0 => get_string('LBL_NO_ROLE_ID', local_userenrols_plugin::PLUGIN_NAME)), get_assignable_roles($this->_customdata['data']->context, ROLENAME_BOTH)); $this->_form->addElement('select', local_userenrols_plugin::FORMID_ROLE_ID, get_string('LBL_ROLE_ID', local_userenrols_plugin::PLUGIN_NAME), $roles); $this->_form->setDefault(local_userenrols_plugin::FORMID_ROLE_ID, $this->_customdata['data']->default_role_id); $this->_form->addHelpButton(local_userenrols_plugin::FORMID_ROLE_ID, 'LBL_ROLE_ID', local_userenrols_plugin::PLUGIN_NAME); $this->_form->disabledIf(local_userenrols_plugin::FORMID_ROLE_ID, local_userenrols_plugin::FORMID_METACOURSE, 'eq', '1'); $this->_form->addElement('header', 'identity', get_string('LBL_GROUP_OPTIONS', local_userenrols_plugin::PLUGIN_NAME)); // Process groups $this->_form->addElement('selectyesno', local_userenrols_plugin::FORMID_GROUP, get_string('LBL_GROUP', local_userenrols_plugin::PLUGIN_NAME)); $this->_form->setDefault(local_userenrols_plugin::FORMID_GROUP, 0); $this->_form->addHelpButton(local_userenrols_plugin::FORMID_GROUP, 'LBL_GROUP', local_userenrols_plugin::PLUGIN_NAME); // Group id selection $groups = array(0 => get_string('LBL_NO_GROUP_ID', local_userenrols_plugin::PLUGIN_NAME)); foreach (groups_get_all_groups($this->_customdata['data']->course->id) as $key => $group_record) { $groups[$key] = $group_record->name; } $this->_form->addElement('select', local_userenrols_plugin::FORMID_GROUP_ID, get_string('LBL_GROUP_ID', local_userenrols_plugin::PLUGIN_NAME), $groups); $this->_form->setDefault(local_userenrols_plugin::FORMID_GROUP_ID, 0); $this->_form->addHelpButton(local_userenrols_plugin::FORMID_GROUP_ID, 'LBL_GROUP_ID', local_userenrols_plugin::PLUGIN_NAME); $this->_form->disabledIf(local_userenrols_plugin::FORMID_GROUP_ID, local_userenrols_plugin::FORMID_GROUP, 'eq', '0'); // Create new if needed $this->_form->addElement('selectyesno', local_userenrols_plugin::FORMID_GROUP_CREATE, get_string('LBL_GROUP_CREATE', local_userenrols_plugin::PLUGIN_NAME)); $this->_form->setDefault(local_userenrols_plugin::FORMID_GROUP_CREATE, 0); $this->_form->addHelpButton(local_userenrols_plugin::FORMID_GROUP_CREATE, 'LBL_GROUP_CREATE', local_userenrols_plugin::PLUGIN_NAME); $this->_form->disabledIf(local_userenrols_plugin::FORMID_GROUP_CREATE, local_userenrols_plugin::FORMID_GROUP, 'eq', '0'); $this->_form->disabledIf(local_userenrols_plugin::FORMID_GROUP_CREATE, local_userenrols_plugin::FORMID_GROUP_ID, 'gt', '0'); $this->_form->addElement('header', 'identity', get_string('LBL_FILE_OPTIONS', local_userenrols_plugin::PLUGIN_NAME)); // File picker $this->_form->addElement('filepicker', local_userenrols_plugin::FORMID_FILES, null, null, $this->_customdata['options']); //$this->_form->addHelpButton(local_userenrols_plugin::FORMID_FILES, 'LBL_FILE', local_userenrols_plugin::PLUGIN_NAME); $this->_form->addRule(local_userenrols_plugin::FORMID_FILES, null, 'required', null, 'client'); $this->add_action_buttons(true, get_string('LBL_IMPORT', local_userenrols_plugin::PLUGIN_NAME)); }
/** * export submitted values * * @param string $elementList list of elements in form * @return array */ function exportValues($elementList = null) { $unfiltered = array(); if (null === $elementList) { // iterate over all elements, calling their exportValue() methods foreach (array_keys($this->_elements) as $key) { if ($this->_elements[$key]->isFrozen() && !$this->_elements[$key]->_persistantFreeze) { $varname = $this->_elements[$key]->_attributes['name']; $value = ''; // If we have a default value then export it. if (isset($this->_defaultValues[$varname])) { $value = $this->prepare_fixed_value($varname, $this->_defaultValues[$varname]); } } else { $value = $this->_elements[$key]->exportValue($this->_submitValues, true); } if (is_array($value)) { // This shit throws a bogus warning in PHP 4.3.x $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } } else { if (!is_array($elementList)) { $elementList = array_map('trim', explode(',', $elementList)); } foreach ($elementList as $elementName) { $value = $this->exportValue($elementName); if (@PEAR::isError($value)) { return $value; } //oh, stock QuickFOrm was returning array of arrays! $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } if (is_array($this->_constantValues)) { $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $this->_constantValues); } return $unfiltered; }
/** * @param string $elementList */ function exportValues($elementList = null) { $unfiltered = array(); if (null === $elementList) { // iterate over all elements, calling their exportValue() methods $emptyarray = array(); foreach (array_keys($this->_elements) as $key) { if ($this->_elements[$key]->isFrozen() && !$this->_elements[$key]->_persistantFreeze) { $value = $this->_elements[$key]->exportValue($emptyarray, true); } else { $value = $this->_elements[$key]->exportValue($this->_submitValues, true); } if (is_array($value)) { // This shit throws a bogus warning in PHP 4.3.x $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } } else { if (!is_array($elementList)) { $elementList = array_map('trim', explode(',', $elementList)); } foreach ($elementList as $elementName) { $value = $this->exportValue($elementName); if (PEAR::isError($value)) { return $value; } //oh, stock QuickFOrm was returning array of arrays! $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } return $unfiltered; }
/** * Returns 'safe' elements' values * * Unlike getSubmitValues(), this will return only the values * corresponding to the elements present in the form. * * @param mixed Array/string of element names, whose values we want. If not set then return all elements. * @access public * @return array An assoc array of elements' values * @throws HTML_QuickForm_Error */ function exportValues($elementList = null) { $values = array(); if (null === $elementList) { // iterate over all elements, calling their exportValue() methods foreach (array_keys($this->_elements) as $key) { $value = $this->_elements[$key]->exportValue($this->_submitValues, true); if (is_array($value)) { // This shit throws a bogus warning in PHP 4.3.x $values = HTML_QuickForm::arrayMerge($values, $value); } } } else { if (!is_array($elementList)) { $elementList = array_map('trim', explode(',', $elementList)); } foreach ($elementList as $elementName) { $value = $this->exportValue($elementName); if (PEAR::isError($value)) { return $value; } $values[$elementName] = $value; } } return $values; }
/** * Returns the form's values * * @access public * @param string name of the page, if not set then returns values for all pages * @return array */ function exportValues($pageName = null) { $data =& $this->container(); $values = array(); if (isset($pageName)) { $pages = array($pageName); } else { $pages = array_keys($data['values']); } foreach ($pages as $page) { // skip elements representing actions foreach ($data['values'][$page] as $key => $value) { if (0 !== strpos($key, '_qf_')) { if (isset($values[$key]) && is_array($value)) { $values[$key] = HTML_QuickForm::arrayMerge($values[$key], $value); } else { $values[$key] = $value; } } } } return $values; }
/** * As usual, to get the group's value we access its elements and call * their exportValue() methods */ function exportValue(&$submitValues, $assoc = false) { $value = null; foreach (array_keys($this->_elements) as $key) { $elementName = $this->_elements[$key]->getName(); if ($this->_appendName) { if (is_null($elementName)) { $this->_elements[$key]->setName($this->getName()); } elseif ('' === $elementName) { $this->_elements[$key]->setName($this->getName() . '[' . $key . ']'); } else { $this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']'); } } $v = $this->_elements[$key]->exportValue($submitValues, $assoc); if ($this->_appendName) { $this->_elements[$key]->setName($elementName); } if (null !== $v) { // Make $value an array, we will use it like one if (null === $value) { $value = array(); } if ($assoc) { // just like HTML_QuickForm::exportValues() $value = HTML_QuickForm::arrayMerge($value, $v); } else { // just like getValue(), but should work OK every time here if (is_null($elementName)) { $value = $v; } elseif ('' === $elementName) { $value[] = $v; } else { $value[$elementName] = $v; } } } } // do not pass the value through _prepareValue, we took care of this already return $value; }
/** * Returns 'safe' elements' values * * Unlike getSubmitValues(), this will return only the values * corresponding to the elements present in the form. * * @param mixed Array/string of element names, whose values we want. If not set then return all elements. * @access public * @return array An assoc array of elements' values * @throws HTML_QuickForm_Error */ function exportValues($elementList = null) { $values = array(); if (null === $elementList) { // iterate over all elements, calling their exportValue() methods foreach (array_keys($this->_elements) as $key) { $value = $this->_elements[$key]->exportValue($this->_submitValues, true); $fldName = null; if (isset($this->_elements[$key]->_attributes['name'])) { //filter the value across XSS vulnerability issues. $fldName = $this->_elements[$key]->_attributes['name']; } if (!in_array($this->_elements[$key]->_type, array('text', 'textarea')) or CRM_Core_HTMLInputCoder::isSkippedField($fldName)) { // …don’t filter, otherwise filter (else clause below) } else { //here value might be array or single value. //so we should iterate and get filtered value. CRM_Core_HTMLInputCoder::encodeInput($value); } if (is_array($value)) { // This shit throws a bogus warning in PHP 4.3.x $values = HTML_QuickForm::arrayMerge($values, $value); } } } else { if (!is_array($elementList)) { $elementList = array_map('trim', explode(',', $elementList)); } foreach ($elementList as $elementName) { $value = $this->exportValue($elementName); //filter the value across XSS vulnerability issues. if (!CRM_Core_HTMLInputCoder::isSkippedField($elementName)) { CRM_Core_HTMLInputCoder::encodeInput($value); } if (PEAR::isError($value)) { return $value; } $values[$elementName] = $value; } } return $values; }
/** * Returns 'safe' elements' values * * Unlike getSubmitValues(), this will return only the values * corresponding to the elements present in the form. * * @param mixed Array/string of element names, whose values we want. If not set then return all elements. * @access public * @return array An assoc array of elements' values * @throws HTML_QuickForm_Error */ function exportValues($elementList = null) { $skipFields = array('widget_code', 'html_message', 'body_html', 'msg_html', 'description', 'intro', 'thankyou_text', 'intro_text', 'page_text', 'body_text', 'footer_text', 'thankyou_footer', 'thankyou_footer_text', 'new_text', 'renewal_text', 'help_pre', 'help_post', 'confirm_title', 'confirm_text', 'confirm_footer_text', 'confirm_email_text', 'event_full_text', 'waitlist_text', 'approval_req_text', 'report_header', 'report_footer', 'cc_id', 'bcc_id', 'premiums_intro_text', 'honor_block_text', 'pay_later_receipt', 'label', 'url', 'msg_text', 'text_message'); $values = array(); if (null === $elementList) { // iterate over all elements, calling their exportValue() methods foreach (array_keys($this->_elements) as $key) { $value = $this->_elements[$key]->exportValue($this->_submitValues, true); $fldName = null; if (isset($this->_elements[$key]->_attributes['name'])) { //filter the value across XSS vulnerability issues. $fldName = $this->_elements[$key]->_attributes['name']; } if (in_array($this->_elements[$key]->_type, array('text', 'textarea')) && !in_array($fldName, $skipFields)) { //here value might be array or single value. //so we should iterate and get filtered value. $this->filterValue($value); } if (is_array($value)) { // This shit throws a bogus warning in PHP 4.3.x $values = HTML_QuickForm::arrayMerge($values, $value); } } } else { if (!is_array($elementList)) { $elementList = array_map('trim', explode(',', $elementList)); } foreach ($elementList as $elementName) { $value = $this->exportValue($elementName); //filter the value across XSS vulnerability issues. if (!in_array($elementName, $skipFields)) { $this->filterValue($value); } if (PEAR::isError($value)) { return $value; } $values[$elementName] = $value; } } return $values; }
/** * Returns a 'safe' element's value * * @param array array of submitted values to search * @param bool whether to return the value as associative array * @access public * @return mixed */ function exportValue(&$submitValues, $assoc = false) { if ($this->_options['actAsGroup']) { return parent::exportValue($submitValues, $assoc); } if ($assoc) { $values = array(); foreach (array_keys($this->_rows) as $key) { foreach (array_keys($this->_rows[$key]) as $key2) { $value = $this->_rows[$key][$key2]->exportValue($submitValues, true); if (is_array($value)) { $values = HTML_QuickForm::arrayMerge($values, $value); } else { $values[$this->_rows[$key][$key2]->getName()] = $value; } } } return $values; } else { return null; } }
/** * Upload and move the file if valid to the uploaded directory. * * @param CRM_Core_Form $page * The CRM_Core_Form object. * @param object $data * The QFC data container. * @param string $pageName * The name of the page which index the data container with. * @param string $uploadName * The name of the uploaded file. */ public function upload(&$page, &$data, $pageName, $uploadName) { // make sure uploadName exists in the QF array // else we skip, CRM-3427 if (empty($uploadName) || !isset($page->_elementIndex[$uploadName])) { return; } // get the element containing the upload $element =& $page->getElement($uploadName); if ('file' == $element->getType()) { if ($element->isUploadedFile()) { // rename the uploaded file with a unique number at the end $value = $element->getValue(); $newName = CRM_Utils_File::makeFileName($value['name']); $status = $element->moveUploadedFile($this->_uploadDir, $newName); if (!$status) { CRM_Core_Error::statusBounce(ts('We could not move the uploaded file %1 to the upload directory %2. Please verify that the \'Temporary Files\' setting points to a valid path which is writable by your web server.', array(1 => $value['name'], 2 => $this->_uploadDir))); } if (!empty($data['values'][$pageName][$uploadName]['name'])) { @unlink($this->_uploadDir . $data['values'][$pageName][$uploadName]); } $value = array('name' => $this->_uploadDir . $newName, 'type' => $value['type']); //CRM-19460 handle brackets if present in $uploadName, similar things we do it for all other inputs. $value = $element->_prepareValue($value, TRUE); $data['values'][$pageName] = HTML_QuickForm::arrayMerge($data['values'][$pageName], $value); } } }