function sendForm($form) { $objForms = new FormModel(); $objEmailer = new Emailer(); $objLayout = new LayoutModel(); $objTemplate = new TemplatesModel(); $formInfo = $objForms->loadForm($form['formSubmit']['id']); $formFields = $objForms->getSubmission($form['submission_id']); $this->view->assign('formFields', $formFields); $layoutInfo = $objLayout->loadLayout(28); $template = $objTemplate->loadTemplateFromKeyname('email-sendform'); // modify email subject if (!empty($form['pageTitle'])) { $subject = $formInfo['emailSubject'] . ' - ' . $form['pageTitle']; } else { if (!empty($form['returnUrlRequest'])) { $subject = $formInfo['emailSubject'] . ' - ' . $form['returnUrlRequest']; } else { $subject = $formInfo['emailSubject']; } } $objEmailer->setFrom($formInfo['emailFrom'], PRODUCT_NAME); $objEmailer->addTo($formInfo['emailTo']); $objEmailer->setSubject($subject); // assign vars to template $this->view->assign('content', $this->view->fetch('fromstring:' . $template['content'])); $this->view->assign('sidebar_left', $this->view->fetch('fromstring:' . $template['left_sidebar'])); $this->view->assign('sidebar_right', $this->view->fetch('fromstring:' . $template['right_sidebar'])); // render template $objEmailer->setBody($this->view->fetch('fromstring:' . $layoutInfo['code']), true); // send email $objEmailer->sendMail(); return true; }
/** * Smarty {form} function plugin * * Type: function<br> * Name: form<br> * Purpose: generates form from database<br> * @author Nathan Gardner <*****@*****.**> */ function smarty_function_form($localparams, &$smarty) { global $params; if (!empty($localparams['identifier'])) { $objForm = new FormModel(); $objAuth = Authentication::getInstance(); $objTemplate = new TemplatesModel(); $objUser = new UserModel($objAuth->user_id); $userInfo = $objUser->getInfo(); $form_id = $objForm->getFormId($localparams['identifier']); if ($form_id) { $formInfo = $objForm->loadForm($form_id); $templateInfo = $objTemplate->loadTemplateFromKeyname('form'); // assign values if already submitted if (!empty($params['formSubmit']['fields']) && !empty($formInfo['fields'])) { foreach ($formInfo['fields'] as &$formField) { foreach ($params['formSubmit']['fields'] as $submittedId => $submittedValue) { if ($formField['id'] == $submittedId) { if ($formField['type'] == 'checkbox' || $formField['type'] == 'radio') { $formField['checked'] = 'checked'; } else { $formField['value'] = $submittedValue; } break; } } } } // assign error flag and message if invalid if (!empty($params['formErrors']) && !empty($formInfo['fields'])) { foreach ($params['formErrors'] as $formError) { foreach ($formInfo['fields'] as &$formField) { if ($formError['field_id'] == $formField['id']) { $formField['hasError'] = true; $formField['errorMsg'] = $formError['errorMsg']; break; } } } } // assign var to template if (!empty($params['formSubmitted'])) { $smarty->assign('formSubmitted', 1); } if (!empty($params['formErrors'])) { $smarty->assign('formErrors', $params['formErrors']); } $smarty->assign('formInfo', $formInfo); $output = $smarty->fetch('fromstring:' . $templateInfo['content']); } else { return 'Unknown form identifier'; } } else { return 'Must pass an identifier'; } return $output; }
public function view() { // get the current form id $id = $this->getId(); $form = new FormModel(); $form->loadByPK($id); // pass form to view $this->getView()->assign('form', $form); // meta decorator $decorator = new Ajde_Crud_Cms_Meta_Decorator(); $this->getView()->assign('decorator', $decorator); // render the temnplate return $this->render(); }
/** * Initialize the object * * @param ContentModel|ModuleModel|FormModel $objElement * @param string $strColumn */ public function __construct($objElement, $strColumn = 'main') { parent::__construct(); // Store the parent element (see #4556) if ($objElement instanceof Model) { $this->objParent = $objElement; } elseif ($objElement instanceof Model\Collection) { $this->objParent = $objElement->current(); } if ($this->strKey == '' || $this->strTable == '') { return; } /** @var Model $strModelClass */ $strModelClass = \Model::getClassFromTable($this->strTable); // Load the model if (class_exists($strModelClass)) { $objHybrid = $strModelClass::findByPk($objElement->{$this->strKey}); if ($objHybrid === null) { return; } $this->objModel = $objHybrid; } else { $objHybrid = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($objElement->{$this->strKey}); if ($objHybrid->numRows < 1) { return; } } $cssID = array(); $this->arrData = $objHybrid->row(); // Get the CSS ID from the parent element (!) $this->cssID = deserialize($objElement->cssID, true); if (isset($objHybrid->attributes)) { $cssID = deserialize($objHybrid->attributes, true); } // Override the CSS ID (see #305) if (!empty($this->cssID[0])) { $cssID[0] = $this->cssID[0]; } // Merge the CSS classes (see #6011) if (!empty($this->cssID[1])) { $cssID[1] = trim($cssID[1] . ' ' . $this->cssID[1]); } $this->cssID = $cssID; $this->typePrefix = $objElement->typePrefix; $arrHeadline = deserialize($objElement->headline); $this->headline = is_array($arrHeadline) ? $arrHeadline['value'] : $arrHeadline; $this->hl = is_array($arrHeadline) ? $arrHeadline['unit'] : 'h1'; $this->strColumn = $strColumn; }
/** * Send lead data using given notification * * @param int $leadId * @param FormModel $form * @param \NotificationCenter\Model\Notification $notification * * @return bool */ public static function send($leadId, \FormModel $form, \NotificationCenter\Model\Notification $notification) { $data = array(); $labels = array(); $leadDataCollection = \Database::getInstance()->prepare("\n SELECT\n name,\n value,\n (SELECT label FROM tl_form_field WHERE tl_form_field.id=tl_lead_data.field_id) AS fieldLabel\n FROM tl_lead_data\n WHERE pid=?\n ")->execute($leadId); // Generate the form data and labels while ($leadDataCollection->next()) { $data[$leadDataCollection->name] = $leadDataCollection->value; $labels[$leadDataCollection->name] = $leadDataCollection->fieldLabel ?: $leadDataCollection->name; } $formHelper = new \NotificationCenter\tl_form(); // Send the notification $result = $notification->send($formHelper->generateTokens($data, $form->row(), array(), $labels)); return !in_array(false, $result); }
/** * Get fields for the form's SObject type * @param object * @return array */ public function getSObjectFields($dc) { $arrOptions = array(); $objFormField = \FormFieldModel::findByPk($dc->id); if ($objFormField === null) { return $arrOptions; } $objForm = \FormModel::findByPk($objFormField->pid); if ($objForm === null) { return $arrOptions; } if ($objForm->useSalesforce && $objForm->salesforceAPIConfig && $objForm->salesforceSObject) { try { $objClient = Salesforce::getClient($objForm->salesforceAPIConfig); $arrConfig = $GLOBALS['TL_SOBJECTS'][$objForm->salesforceSObject]; $strClass = $arrConfig['class']; if (class_exists($strClass)) { $objResults = $objClient->describeSObjects(array($strClass::getType())); $arrFields = $objResults[0]->getFields(); foreach ($arrFields as $field) { if (!$field->isCreateable()) { continue; } $arrOptions[$field->getName()] = $field->getName(); } } } catch (\Exception $e) { } } return $arrOptions; }
private function saveToDb($params) { $objAuth = Authentication::getInstance(); $user_id = $objAuth->user_id; $objForm = new FormModel(); $saveData = array(); $saveData['form_id'] = $params['formSubmit']['id']; $saveData['user_id'] = $user_id; $saveData['fromPage'] = !empty($params['returnUrlRequest']) ? $params['returnUrlRequest'] : false; if (!empty($params['formSubmit']['fields'])) { foreach ($params['formSubmit']['fields'] as $fieldId => $value) { $fieldInfo = array(); $fieldInfo['field_id'] = intval($fieldId); $fieldInfo['value'] = $value; $saveData['fields'][] = $fieldInfo; } } if (!empty($params['formSubmit']['userfields'])) { foreach ($params['formSubmit']['userfields'] as $fieldId => $value) { $fieldInfo = array(); $fieldInfo['field_id'] = intval($fieldId); $fieldInfo['value'] = $value; $saveData['fields'][] = $fieldInfo; } } $submission_id = $objForm->saveSubmission($saveData); return $submission_id; }
public function afterValidate() { if (!$this->hasErrors()) { $this->sendEmail(); $this->success_message = Lang::t('Check this email ({email}) for instructions on how to get a new password.If you don\'t get email please check your spam and mark it as "not spam"', array('{email}' => $this->user_model->email)); } return parent::afterValidate(); }
/** * Generate the checkout step * @return string */ public function generate() { $this->objForm = new Form($this->objModule->getFormId(), 'POST', function ($haste) { return \Input::post('FORM_SUBMIT') === $haste->getFormId(); }); if ($this->objModule->iso_order_conditions) { $objFormConfig = \FormModel::findByPk($this->objModule->iso_order_conditions); if (null === $objFormConfig) { throw new \InvalidArgumentException('Order condition form "' . $this->objModule->iso_order_conditions . '" not found.'); } $this->objForm->setTableless($objFormConfig->tableless); $this->objForm->addFieldsFromFormGenerator($this->objModule->iso_order_conditions, function ($strName, &$arrDca) { $arrDca['value'] = $_SESSION['FORM_DATA'][$strName] ?: $arrDca['value']; return true; }); } if (!empty($GLOBALS['ISO_HOOKS']['orderConditions']) && is_array($GLOBALS['ISO_HOOKS']['orderConditions'])) { foreach ($GLOBALS['ISO_HOOKS']['orderConditions'] as $callback) { \System::importStatic($callback[0])->{$callback[1]}($this->objForm, $this->objModule); } } if (!$this->objForm->hasFields()) { $this->blnError = false; return ''; } // Change enctype if there are uploads if ($this->objForm->hasUploads()) { $this->objModule->Template->enctype = 'multipart/form-data'; } if ($this->objForm->isSubmitted()) { $this->blnError = !$this->objForm->validate(); $_SESSION['FORM_DATA'] = is_array($_SESSION['FORM_DATA']) ? $_SESSION['FORM_DATA'] : array(); foreach (array_keys($this->objForm->getFormFields()) as $strField) { if ($this->objForm->getWidget($strField) instanceof \uploadable) { $arrFile = $_SESSION['FILES'][$strField]; $varValue = str_replace(TL_ROOT . '/', '', dirname($arrFile['tmp_name'])) . '/' . rawurlencode($arrFile['name']); } else { $varValue = $this->objForm->fetch($strField); } $_SESSION['FORM_DATA'][$strField] = $varValue; } } else { $blnError = false; foreach (array_keys($this->objForm->getFormFields()) as $strField) { // Clone widget because otherwise we add errors to the original widget instance $objClone = clone $this->objForm->getWidget($strField); $objClone->validate(); if ($objClone->hasErrors()) { $blnError = true; break; } } $this->blnError = $blnError; } $objTemplate = new \Isotope\Template('iso_checkout_order_conditions'); $this->objForm->addToTemplate($objTemplate); return $objTemplate->parse(); }
/** * Clear the cache of the forms when a validation setting has changed. * * @param \DataContainer $dataContainer The data container. * * @return void */ public function clearCache($dataContainer) { $collection = \FormModel::findBy(['fv_active=1', 'fv_setting=?'], $dataContainer->id); if ($collection) { foreach ($collection as $form) { $this->cache->remove($form->id); } } }
/** * Validates a field. * * @param \FormFieldModel $formField * @param int $step * * @return bool */ public function validateField(\FormFieldModel $formField, $step) { $class = $GLOBALS['TL_FFL'][$formField->type]; if (!class_exists($class)) { return true; } /** @var \Widget $widget */ $widget = new $class($formField->row()); $widget->required = $formField->mandatory ? true : false; // Needed for the hook $form = $this->createDummyForm(); // HOOK: load form field callback if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) { foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) { $objCallback = \System::importStatic($callback[0]); $widget = $objCallback->{$callback[1]}($widget, $this->getFormId(), $this->formModel->row(), $form); } } // Validation (needs to set POST values because the widget class searches // only in POST values :-( // This should only happen if value is not currently submitted and if // the value is neither submitted in POST nor in the session, we have // to default it to an empty string so the widget validates for mandatory // fields $fakeValidation = false; if (!isset($_POST[$widget->name])) { if ($this->isStoredInData($widget->name, $step)) { $value = $this->fetchFromData($widget->name, $step); } else { $value = ''; } \Input::setPost($formField->name, $value); $fakeValidation = true; } $widget->validate(); // Reset fake validation if ($fakeValidation) { \Input::setPost($formField->name, null); } // Special hack for upload fields because they delete $_FILES and thus // multiple validation calls will fail - sigh if ($widget instanceof \uploadable && isset($_SESSION['FILES'][$widget->name])) { $_FILES[$widget->name] = $_SESSION['FILES'][$widget->name]; } // HOOK: validate form field callback if (isset($GLOBALS['TL_HOOKS']['validateFormField']) && is_array($GLOBALS['TL_HOOKS']['validateFormField'])) { foreach ($GLOBALS['TL_HOOKS']['validateFormField'] as $callback) { $objCallback = \System::importStatic($callback[0]); $widget = $objCallback->{$callback[1]}($widget, $this->getFormId(), $this->formModel->row(), $form); } } return !$widget->hasErrors(); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.Superglobals) */ public function generate() { if (TL_MODE === 'BE') { $template = new \BackendTemplate('be_wildcard'); $subform = \FormModel::findByPk($this->subform); $template->wildcard = sprintf('### %s ###', $GLOBALS['TL_LANG']['tl_form_field']['subform'][0]); $template->id = $this->id; $template->link = $subform->title; $template->href = sprintf('contao/main.php?do=form&table=tl_form_field&id=%s&rt=%s', $this->subform, \RequestToken::get()); return $template->parse(); } return ''; }
/** * Get all available forms. * * @param \DataContainer $dataContainer The data container driver. * * @return array */ public function getSubformOptions($dataContainer) { $options = array(); if ($dataContainer->activeRecord) { $collection = \FormModel::findBy(['tl_form.id !=?'], $dataContainer->activeRecord->pid, ['order' => 'title']); if ($collection) { foreach ($collection as $form) { $options[$form->id] = sprintf('%s [%s]', $form->title, $form->id); } } } return $options; }
/** * Generate label for this record. * * @param array * @param string * * @return string */ public function getLabel($row, $label) { $objForm = \FormModel::findById($row['master_id']); if ($objForm != null && $objForm->encryptLeadsData) { $arrTokens = array('created' => \Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $row['created'])); $objData = \Database::getInstance()->prepare("SELECT * FROM tl_lead_data WHERE pid=?")->execute($row['id']); while ($objData->next()) { Haste\Util\StringUtil::flatten(deserialize(\Encryption::decrypt($objData->value)), $objData->name, $arrTokens); } return \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($objForm->leadLabel, $arrTokens); } return parent::getLabel($row, $label); }
public function read() { /*$Form = M('Form'); $data = $Form -> find(); var_dump($data);exit; if($data){ $this -> assign('data',$data); }else{ $this -> error('数据错误'); } $this -> display();*/ $a = FormModel::getUser(); var_dump($a); }
public function generateTokenLink($arrToSave, &$arrFiles, $intOldId, &$arrForm, $arrLabels) { $this->arrSubmitted = $arrToSave; // generate token & token link if (($objForm = \FormModel::findByPk($arrForm['id'])) !== null && ($objPageActivation = \PageModel::findByPk($objForm->jumpTo_activation)) !== null) { $strToken = md5(uniqid(mt_rand(), true)); $this->arrSubmitted[$objForm->formFieldToken] = $strToken; $strTokenLink = rtrim(\Environment::get('base'), '/') . '/' . $this->generateFrontendUrl($objPageActivation->row()) . '?token=' . $strToken . '&vid=' . $arrForm['id']; $this->arrSubmitted[$objForm->formFieldTokenLink] = $strTokenLink; } // add recipient if field's been checked if ($this->arrSubmitted[$objForm->formFieldNewsletter] == 'yes' && $this->arrSubmitted['email']) { $this->addRecipient($this->arrSubmitted['email'], deserialize($objForm->newsletters, true), $objForm->newsletterSubscribeMailText, $objForm->newsletterSubscribeJumpTo); } return $this->arrSubmitted; }
/** * Generate the checkout step * @return string */ public function generate() { $objFormConfig = \FormModel::findByPk($this->objModule->iso_order_conditions); $this->objForm = new Form($this->objModule->getFormId(), 'POST', function ($haste) { return \Input::post('FORM_SUBMIT') === $haste->getFormId(); }, (bool) $objFormConfig->tableless); // Don't catch the exception here because we want it to be shown to the user $this->objForm->addFieldsFromFormGenerator($this->objModule->iso_order_conditions, function ($strName, &$arrDca) { $arrDca['value'] = $_SESSION['FORM_DATA'][$strName] ?: $arrDca['value']; return true; }); // Change enctype if there are uploads if ($this->objForm->hasUploads()) { $this->objModule->Template->enctype = 'multipart/form-data'; } if ($this->objForm->isSubmitted()) { $this->blnError = !$this->objForm->validate(); $_SESSION['FORM_DATA'] = is_array($_SESSION['FORM_DATA']) ? $_SESSION['FORM_DATA'] : array(); foreach (array_keys($this->objForm->getFormFields()) as $strField) { if ($this->objForm->getWidget($strField) instanceof \uploadable) { $arrFile = $_SESSION['FILES'][$strField]; $varValue = str_replace(TL_ROOT . '/', '', dirname($arrFile['tmp_name'])) . '/' . rawurlencode($arrFile['name']); } else { $varValue = $this->objForm->fetch($strField); } $_SESSION['FORM_DATA'][$strField] = $varValue; } } else { $blnError = false; foreach (array_keys($this->objForm->getFormFields()) as $strField) { // Clone widget because otherwise we add errors to the original widget instance $objClone = clone $this->objForm->getWidget($strField); $objClone->validate(); if ($objClone->hasErrors()) { $blnError = true; break; } } $this->blnError = $blnError; } $objTemplate = new \Isotope\Template('iso_checkout_order_conditions'); $this->objForm->addToTemplate($objTemplate); return $objTemplate->parse(); }
public function compile() { if (($strToken = \Input::get('token')) && ($strVotingId = \Input::get('vid')) && ($objForm = \FormModel::findByPk($strVotingId)) !== null) { $db = \Database::getInstance(); $objTokenCheck = $db->prepare('SELECT * FROM tl_formdata_details fdt INNER JOIN tl_formdata fd ON fdt.pid=fd.id INNER JOIN tl_form f ON fd.form=f.title WHERE fdt.ff_name=? AND fdt.value=? AND f.id=?')->limit(1)->execute($objForm->formFieldToken, $strToken, $strVotingId); if ($objTokenCheck->numRows > 0) { // check if already activated $objTokenCheckActivated = $db->prepare('SELECT * FROM tl_formdata_details WHERE ff_name=? AND pid=?')->limit(1)->execute($objForm->formFieldActivated, $objTokenCheck->pid); if ($objTokenCheckActivated->numRows > 0) { if ($objTokenCheckActivated->value) { $this->Template->message = array(MESSAGE_WARNING, $GLOBALS['TL_LANG']['email_voting']['tokenAlreadyUsed']); } else { $this->Template->message = array(MESSAGE_SUCCESS, $GLOBALS['TL_LANG']['email_voting']['votingSuccessful']); $db->prepare('UPDATE tl_formdata_details SET value=? WHERE ff_name=? AND pid=?')->execute(time(), $objForm->formFieldActivated, $objTokenCheck->pid); } } } else { $this->Template->message = array(MESSAGE_ERROR, $GLOBALS['TL_LANG']['email_voting']['tokenNotFound']); } } }
/** * prepare */ public function prepare() { // load backend user $this->import('BackendUser', 'User'); // check permission if ($this->User->isAdmin || $this->User->hasAccess('form', 'modules') && isset($this->User->forms) && is_array($this->User->forms)) { // check if table exists if (!$this->Database->tableExists('tl_form')) { return; } // get all forms $objForm = \FormModel::findAll(array('order' => 'title')); // there are at minimum one form if (!is_null($objForm) && $objForm->count()) { // prepare directentry array $arrDirectEntry = array(); // set counter $intCounter = 1; // do this foreach page while ($objForm->next()) { // check page permission if ($this->User->isAdmin || in_array($objForm->id, $this->User->forms)) { // set the icon url and title $arrDirectEntry[$intCounter]['icons']['page']['url'] = 'contao/main.php?do=form&table=tl_form_field&id=' . $objForm->id; $arrDirectEntry[$intCounter]['icons']['page']['title'] = 'form'; $arrDirectEntry[$intCounter]['icons']['page']['icon'] = 'form'; // set the page url and title $arrDirectEntry[$intCounter]['name']['url'] = 'contao/main.php?do=form&table=tl_form_field&id=' . $objForm->id; $arrDirectEntry[$intCounter]['name']['title'] = $objForm->title; $arrDirectEntry[$intCounter]['name']['link'] = strlen($objForm->title) > 17 ? substr($objForm->title, 0, 15) . '...' : $objForm->title; // add one to counter $intCounter++; } } // add to direcentries service $this->import('DirectEntries'); $this->DirectEntries->addDirectEntry('content', 'form', $arrDirectEntry); } } }
/** * Parses the warden config. * * @return array */ public function toArray() { $attr = !empty($this->getWarden()) ? $this->getWarden() : null; if (empty($attr)) { $attr = empty($this->getVisible()) ? $this->getFillable() : $this->getVisible(); } $returnable = []; $f_model = \FormModel::using('plain')->withModel($this); foreach ($attr as $old => $new) { if (!empty($relations = $f_model->getRelationalDataAndModels($this, $old))) { $returnable[$new] = $relations; } if (stripos($old, '_id') !== false) { if (!empty($this->{$new})) { $returnable[$new] = $relations; } } else { if (isset($this->{$old})) { $returnable[$new] = $this->{$old}; } } } return $returnable; }
/** * Get the maximum file size that is allowed for file uploads * * @return integer * * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0. * Use $this->objModel->getMaxUploadFileSize() instead. */ protected function getMaxFileSize() { trigger_error('Using Form::getMaxFileSize() has been deprecated and will no longer work in Contao 5.0. Use $this->objModel->getMaxUploadFileSize() instead.', E_USER_DEPRECATED); return $this->objModel->getMaxUploadFileSize(); }
private function create($id = null) { $pdo = DatabaseFactory::getFactory()->getConnection(); $sql = "SHOW FULL COLUMNS FROM " . $this->table; $fields = $pdo->prepare($sql); $fields->execute(); $results = $fields->fetchAll(); //check to get the fields we want form our $selectcolumns, if needed if (count($this->fields) < 0) { //need to mlogic here, so its disabled (allow/disallow editing based on auth foreach ($results as $values) { if (in_array($values->Field, $this->fields)) { $columns[] = $values; } } } else { //or else just get all of them.. $columns = $results; } //if we're given a key-value, then we are looking for a specific row. // Get the values of the row and insert them $data = null; //initialize if (isset($id)) { //if we're not given specific fields, then we're getting every field $pdo = DatabaseFactory::getFactory()->getConnection(); $sql = "SELECT * FROM " . $this->table . " WHERE id = " . $id; $query = $pdo->prepare($sql); $query->execute(); $data = $query->fetchObject(); } $title = ucwords(str_replace('_', ' ', $this->table)); //splits table name, replaces the underscore (naming convention) and caps the first letter of each resulting word $t = ' <div class="col-lg-5" /> <h3>' . $title . '</h3> <form id="crud_' . $this->table . '_form" class="crudform " method="post" action="?action=update"> <input type="hidden" name="table" value="' . $this->table . '" readonly />'; foreach ($columns as $col) { $colname = $col->Field; $value = null; // this should set the field values and choose the fields if (!empty($data)) { $value = $data->{$colname}; } if ($col->Key == 'PRI') { $t .= Fields::hidden($colname, $value, $colname); } else { if (isset($this->select) && $colname == $this->select) { $list = array(); $options = FormModel::getrecord($this->optiontable); foreach ($options as $k => $v) { $list[$v->id] = $v->name; } $t .= Fields::select($colname, null, $list, $value); } else { if ($colname == 'user_editor') { $t .= Fields::hidden('user_editor', Session::get('user_id')); } else { if (strpos($colname, '_ID')) { $tbl = str_replace('_ID', '', $colname); $tbl = str_replace('FK', '', $tbl); $tbl = lcfirst($tbl); $t .= Fields::selectgen($colname, $col->Comment, $tbl, true, $value); } else { $type = $col->Type; switch ($type) { case strpos($type, 'int'): case strpos($type, 'smallint'): case strpos($type, 'bigint'): $t .= Fields::number($colname, $value, ucfirst($colname), $col->Comment); break; case strpos($type, 'tinyint'): $t .= Fields::bool('active', $col->Comment, 'Active', 'Inactive', $value); break; case strpos($type, 'char'): case strpos($type, 'varchar'): case strpos($type, 'tinytext'): case strpos($type, 'text'): $t .= Fields::text($colname, $value, ucfirst($colname), $col->Comment); break; case strpos($type, 'longtext'): case strpos($type, 'mediumtext'): $t .= Fields::textarea($colname, $value, ucfirst($colname), $col->Comment); break; case 'date': $t .= Fields::date($colname, $value, ucfirst($colname), $col->Comment); break; case strpos($type, 'timestamp'): if ($colname == 'updated') { $t .= Fields::hidden($colname, date('Y-m-d H:i:s')); } else { $t .= ''; //do not edit time stamp } break; case strpos($type, 'time'): $t .= Fields::date($colname, $value, ucfirst($colname), ucfirst($colname)); case strpos($type, 'datetime'): $t .= Fields::date($colname, $value, ucfirst($colname), ucfirst($colname)); break; default: $t .= Fields::text($colname); } } } } } } $t .= '<br/><br/><input type="submit" class="btn btn-success" /> <a href="?action=index" class="btn btn-info" style="float: right" >Home</a>'; $t .= '</form> </div>'; return $t; }
function actionExportData($params = '') { $exportData = array(); if (!empty($params['form_id']) && !empty($params['doexport']) && !empty($params['startDate']) && !empty($params['endDate'])) { $startDate = date("Y-m-d", strtotime($params['startDate'])); $endDate = date("Y-m-d", strtotime($params['endDate'])); $form_id = intval($params['form_id']); $objForm = new FormModel(); $formData = $objForm->getSubmissions($form_id, $startDate, $endDate); if (!empty($formData)) { $formName = $formData[0]['form_name']; foreach ($formData as $submission) { $exportDataRecord = array(); $exportDataRecord['date'] = $submission['cDate']; if (!empty($submission['fields'])) { foreach ($submission['fields'] as $submitField) { $exportDataRecord[$submitField['name']] = $submitField['value']; } } $exportData[] = $exportDataRecord; } } if (!empty($exportData)) { $headers = array_keys($exportData[0]); header("Content-type: application/CSV"); header("Content-disposition: attachment; filename=" . urlencode($formName) . "_export.csv"); foreach ($headers as $header) { echo '"' . $header . '",'; } echo "\r\n"; foreach ($exportData as $exportRecord) { foreach ($exportRecord as $value) { echo '"' . $value . '",'; } echo "\r\n"; } } } }
public function save($message = true) { Yii::app()->settings->set('contacts', $this->attributes); parent::save($message); }
public function save($message = true) { Yii::app()->settings->set('shop', $this->attributes); $this->saveWatermark(); parent::save($message); }
private function makeform($id) { $results = []; foreach (get_object_vars($this->activeclass) as $key) { $results[] = $key; } $pdo = DatabaseFactory::getFactory()->getConnection(); $sql = "SHOW FULL COLUMNS FROM " . $this->table; $fields = $pdo->prepare($sql); $fields->execute(); //$results = $fields->fetchAll(); //check to get the fields we want form our $selectcolumns, if needed if (count($this->fields) < 0) { //need to logic here, so its disabled (allow/disallow editing based on auth foreach ($results as $values) { if (in_array($values->name, $this->fields)) { $columns[] = $values; } } } else { //or else just get all of them.. $columns = $results; } $data = null; //initialize if (isset($id)) { //if we're not given specific fields, then we're getting every field $pdo = DatabaseFactory::getFactory()->getConnection(); $sql = "SELECT * FROM " . $this->table . " WHERE id = " . $id; $query = $pdo->prepare($sql); $query->execute(); $data = $query->fetchObject(); } $title = ucwords(str_replace('_', ' ', $this->table)); //splits table name, replaces the underscore (naming convention) and caps the first letter of each resulting word //form layouts: $cl = count($columns); $colswanted = $cl < 12 ? 2 : 3; $colslegth = $cl / $colswanted; $t = ' <h3>' . $title . '</h3> <hr/> <div class="row"> <form id="crud_' . $this->table . '_form" class="crudform " method="post" action="?action=update&table=' . $this->table . '"> <input type="hidden" name="table" value="' . $this->table . '" readonly /> <div class="col-md-4" >'; $count = 0; //counter for the form columns foreach ($columns as $col) { //$colname = $col->Field; $colname = $col->name; $value = null; // this should set the field values and choose the fields if (!empty($data)) { $value = $data->{$colname}; } //begin printing fields if ($col->name == 'id') { $t .= Fields::hidden($colname, $value, $colname); } else { if (isset($this->select) && $colname == $this->select) { $list = array(); $options = FormModel::getrecord($this->optiontable); foreach ($options as $k => $v) { $list[$v->id] = $v->name; } $t .= Fields::select($colname, null, $list, $value); } else { if ($colname == 'editor' || $colname == 'created' || $colname == 'updated') { $t .= ''; } else { if (strpos($colname, '_type')) { $t .= Fields::selectgen($colname, $col->label, $colname, true, $value); } else { if (strpos($colname, 'users')) { $t .= ''; } else { if (strpos($colname, '_id')) { $tbl = str_replace('_id', '', $colname); $tbl = lcfirst($tbl); $t .= Fields::selectgen($colname, $col->label, $tbl, true, $value); } else { $type = $col->type; switch ($type) { case strpos($type, 'int'): case strpos($type, 'smallint'): case strpos($type, 'bigint'): $t .= Fields::number($colname, $value, ucfirst($colname), $col->label); break; case strpos($type, 'tinyint'): $t .= Fields::bool('active', $col->label, 'Active', 'Inactive', $value); break; case strpos($type, 'char'): case strpos($type, 'varchar'): case strpos($type, 'tinytext'): case strpos($type, 'text'): $t .= Fields::text($colname, $value, ucfirst($colname), $col->label); break; case strpos($type, 'longtext'): case strpos($type, 'mediumtext'): $t .= Fields::textarea($colname, $value, ucfirst($colname), $col->label); break; case strpos($type, 'timestamp'): if ($colname == 'updated') { $t .= Fields::hidden($colname, date('Y-m-d H:i:s')); } else { $t .= ''; //do not edit time stamp } break; case strpos($type, 'time'): case strpos($type, 'date'): $t .= Fields::date($colname, $value, ucfirst($colname), $col->label); break; case strpos($type, 'year'): $t .= Fields::year($colname, $value, ucfirst($colname), $col->label); break; case strpos($type, 'datetime'): $t .= Fields::date($colname, $value, ucfirst($colname), ucfirst($colname)); break; default: $t .= Fields::text($colname); } } } } } } } $count++; if ($count > $colslegth) { $t .= '</div><div class="col-md-4" >'; $count = 0; } } $t .= '<br/><input type="submit" class="btn btn-success" /> <a href="?action=index&id=' . $id . '&table=' . $this->table . ' " class="btn btn-info" style="float: right" >Home</a></div></div>'; $t .= '</form> '; return $t; }
/** * Get the maximum file size that is allowed for file uploads * * @return integer */ protected function getMaxFileSize() { return $this->objModel->getMaxUploadFileSize(); // Backwards compatibility }
/** * Replace InsertTags. * * @param string $tag * * @return int|false */ public function replaceTags($tag) { if (strpos($tag, 'mp_forms::') === false) { return false; } $chunks = explode('::', $tag); $formId = $chunks[1]; $value = $chunks[2]; $form = \FormModel::findByPk($formId); $manager = new MPFormsFormManager($form->id); switch ($value) { case 'current': return (int) $manager->getCurrentStep() + 1; case 'total': return $manager->getNumberOfSteps(); case 'percentage': return ($manager->getCurrentStep() + 1) / $manager->getNumberOfSteps() * 100; case 'numbers': return $manager->getCurrentStep() + 1 . ' / ' . $manager->getNumberOfSteps(); } }
/** * Generate a form and return it as string * * @param mixed $varId A form ID or a Model object * * @return string The form HTML markup */ protected function getForm($varId) { if (is_object($varId)) { $objRow = $varId; } else { if ($varId == '') { return ''; } $objRow = \FormModel::findByIdOrAlias($varId); if ($objRow === null) { return ''; } } $objRow->typePrefix = 'ce_'; $objRow->form = $objRow->id; $objElement = new \Form($objRow); $strBuffer = $objElement->generate(); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getForm']) && is_array($GLOBALS['TL_HOOKS']['getForm'])) { foreach ($GLOBALS['TL_HOOKS']['getForm'] as $callback) { $this->import($callback[0]); $strBuffer = $this->{$callback}[0]->{$callback}[1]($objRow, $strBuffer); } } return $strBuffer; }
/** * Generate a form and return it as string * * @param mixed $varId A form ID or a Model object * @param string $strColumn The column the form is in * * @return string The form HTML markup */ public static function getForm($varId, $strColumn = 'main') { if (is_object($varId)) { $objRow = $varId; } else { if ($varId == '') { return ''; } $objRow = \FormModel::findByIdOrAlias($varId); if ($objRow === null) { return ''; } } $objRow->typePrefix = 'ce_'; $objRow->form = $objRow->id; $objElement = new \Form($objRow, $strColumn); $strBuffer = $objElement->generate(); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getForm']) && is_array($GLOBALS['TL_HOOKS']['getForm'])) { foreach ($GLOBALS['TL_HOOKS']['getForm'] as $callback) { $strBuffer = static::importStatic($callback[0])->{$callback[1]}($objRow, $strBuffer, $objElement); } } return $strBuffer; }