有关 QForm 类的详细使用,请参考开发者手册的相关章节。
Author: YuLei Liao (liaoyulei@qeeyuan.com)
Inheritance: extends QForm_Group
Example #1
0
    /**
     * 渲染一个表单
     *
     * @param QContext $context
     * @param QForm $form
     * @param boolean $return
     */
    static function render(QContext $context, QForm $form, $return = false)
    {
        $error_messages = $form->error_messages;
        if (!is_array($error_messages)) {
            $error_messages = array();
        }
        $id = $form->id();
        $action = htmlspecialchars($form->action);
        $out = <<<EOT

<form name="{$id}" id="{$id}" action="{$action}" method="post">

EOT;
        foreach ($form as $item) {
            $out .= self::_renderItem($context, $item, $error_messages);
        }
        $out .= <<<EOT

</form>

EOT;
        if (!$return) {
            echo $out;
            $out = null;
        }
        return $out;
    }
 function actionIndex()
 {
     $page = intval($this->_context->page);
     if ($page < 1) {
         $page = 1;
     }
     $form = new QForm('article', url('article/update'));
     //查询参数
     $agrs = null;
     //条件查询
     if (!empty($this->_context->find)) {
         $condition = null;
         $sortId = isset($this->_context->sorts) ? intval($this->_context->sorts) : null;
         $title = isset($this->_context->keywords) ? trim($this->_context->keywords) : null;
         //			$QCon = new QDB_Cond();
         //			if($sortId !=0){
         //				$QCon ->andCond('sort_id =?',$sortId);
         //			}
         //
         //			if(isset($title)){
         //				$QCon ->andCond('title like ?','%'.$title.'%');
         //			}
         if ($sortId != 0) {
             $condition .= "1 AND sort_id ={$sortId}";
         }
         if (!empty($title)) {
             $condition .= '1 AND title like ' . '\'%' . $title . '%\'';
         }
         $select = Articles::find($condition)->order('order_num DESC');
         $agrs = array('sorts' => $sortId, 'keywords' => $title, 'find' => 1);
     } else {
         //查询所有
         $select = Articles::find()->order('order_num DESC');
     }
     $select->limitPage($page, 20);
     $pagenation = $select->getPagination();
     $news = $select->query('newsort,user');
     //构建查询表单
     $findForm = new QForm('new_find', url('article/index'));
     $findForm->add(QForm::ELEMENT, 'keywords', array('_ui' => 'textbox', '_label' => '文章的标题'))->add(QForm::ELEMENT, 'sorts', array('_ui' => 'dropdownlist'))->add(QForm::ELEMENT, 'find', array('_ui' => 'hidden', 'value' => '1'));
     //查询新闻类别的子类信息
     $new = new Articles();
     $findForm['sorts']->items = $new->sorts;
     unset($new);
     $this->_view['form'] = $form;
     $this->_view['news'] = $news;
     $this->_view['pagination'] = $pagenation;
     $this->_view['findform'] = $findForm;
     $this->_view['agrs'] = $agrs;
 }
 /**
  * 茶叶的列表
  *
  */
 function actionIndex()
 {
     //得到页码
     $page = intval($this->_context->page);
     if ($page < 1) {
         $page = 1;
     }
     $agrs = null;
     if (!empty($this->_context->find)) {
         //查询新闻
         $condition = null;
         $type = isset($this->_context->type) ? intval($this->_context->type) : null;
         $name = isset($this->_context->name) ? trim($this->_context->name) : null;
         //			$QCon = new QDB_Cond();
         //			if($sortId !=0){
         //				$QCon ->andCond('sort_id =?',$sortId);
         //			}
         //
         //			if(isset($title)){
         //				$QCon ->andCond('title like ?','%'.$title.'%');
         //			}
         if ($type != -1) {
             $condition .= "1 AND type_id ={$type}";
         }
         if (!empty($name)) {
             $condition .= '1 AND name like ' . '\'%' . $name . '%\'';
         }
         $tea = Tea::find($condition)->order('order_num DESC');
         $agrs = array('type' => $type, 'name' => $name, 'find' => 1);
     } else {
         $tea = Tea::find()->order('order_num DESC');
     }
     $tea->limitPage($page, 20);
     //分页信息
     $pagination = $tea->getPagination();
     $teas = $tea->query('teatype');
     //构建查询表单
     $findForm = new QForm('tea_find', url('tea/index'));
     $findForm->add(QForm::ELEMENT, 'name', array('_ui' => 'textbox', '_label' => '茶叶名'))->add(QForm::ELEMENT, 'type', array('_ui' => 'admin_typelist'))->add(QForm::ELEMENT, 'find', array('_ui' => 'hidden', 'value' => '1'));
     //添加茶叶类别的列表信息
     $teaType = new TeaType();
     $findForm['type']->items = $teaType->list;
     unset($teaType);
     $this->_view['findform'] = $findForm;
     $this->_view['agrs'] = $agrs;
     $this->_view['pagination'] = $pagination;
     $this->_view['teas'] = $teas;
 }
 protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroFileProgresses = new NarroFileProgressDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroFileProgresses->CssClass = 'datagrid';
     $this->dtgNarroFileProgresses->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroFileProgresses->Paginator = new QPaginator($this->dtgNarroFileProgresses);
     $this->dtgNarroFileProgresses->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_file_progress_edit.php';
     $this->dtgNarroFileProgresses->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_file_progress's properties, or you
     // can traverse down QQN::narro_file_progress() to display fields that are down the hierarchy)
     $this->dtgNarroFileProgresses->MetaAddColumn('FileProgressId');
     $this->dtgNarroFileProgresses->MetaAddColumn(QQN::NarroFileProgress()->File);
     $this->dtgNarroFileProgresses->MetaAddColumn(QQN::NarroFileProgress()->Language);
     $this->dtgNarroFileProgresses->MetaAddColumn('FileMd5');
     $this->dtgNarroFileProgresses->MetaAddColumn('Header');
     $this->dtgNarroFileProgresses->MetaAddColumn('TotalTextCount');
     $this->dtgNarroFileProgresses->MetaAddColumn('ApprovedTextCount');
     $this->dtgNarroFileProgresses->MetaAddColumn('FuzzyTextCount');
     $this->dtgNarroFileProgresses->MetaAddColumn('ProgressPercent');
     $this->dtgNarroFileProgresses->MetaAddColumn('Export');
 }
 protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroLanguages = new NarroLanguageDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroLanguages->CssClass = 'datagrid';
     $this->dtgNarroLanguages->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroLanguages->Paginator = new QPaginator($this->dtgNarroLanguages);
     $this->dtgNarroLanguages->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_language_edit.php';
     $this->dtgNarroLanguages->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_language's properties, or you
     // can traverse down QQN::narro_language() to display fields that are down the hierarchy)
     $this->dtgNarroLanguages->MetaAddColumn('LanguageId');
     $this->dtgNarroLanguages->MetaAddColumn('LanguageName');
     $this->dtgNarroLanguages->MetaAddColumn('LanguageCode');
     $this->dtgNarroLanguages->MetaAddColumn('CountryCode');
     $this->dtgNarroLanguages->MetaAddColumn('DialectCode');
     $this->dtgNarroLanguages->MetaAddColumn('Encoding');
     $this->dtgNarroLanguages->MetaAddColumn('TextDirection');
     $this->dtgNarroLanguages->MetaAddColumn('SpecialCharacters');
     $this->dtgNarroLanguages->MetaAddColumn('PluralForm');
     $this->dtgNarroLanguages->MetaAddColumn('Active');
 }
 protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroLogs = new NarroLogDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroLogs->CssClass = 'datagrid';
     $this->dtgNarroLogs->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroLogs->Paginator = new QPaginator($this->dtgNarroLogs);
     $this->dtgNarroLogs->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_log_edit.php';
     $this->dtgNarroLogs->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_log's properties, or you
     // can traverse down QQN::narro_log() to display fields that are down the hierarchy)
     $this->dtgNarroLogs->MetaAddColumn('LogId');
     $this->dtgNarroLogs->MetaAddColumn(QQN::NarroLog()->Language);
     $this->dtgNarroLogs->MetaAddColumn(QQN::NarroLog()->Project);
     $this->dtgNarroLogs->MetaAddColumn(QQN::NarroLog()->User);
     $this->dtgNarroLogs->MetaAddColumn('Message');
     $this->dtgNarroLogs->MetaAddColumn('Priority');
     $this->dtgNarroLogs->MetaAddColumn('Date');
 }
 protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroFiles = new NarroFileDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroFiles->CssClass = 'datagrid';
     $this->dtgNarroFiles->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroFiles->Paginator = new QPaginator($this->dtgNarroFiles);
     $this->dtgNarroFiles->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_file_edit.php';
     $this->dtgNarroFiles->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_file's properties, or you
     // can traverse down QQN::narro_file() to display fields that are down the hierarchy)
     $this->dtgNarroFiles->MetaAddColumn('FileId');
     $this->dtgNarroFiles->MetaAddColumn('FileName');
     $this->dtgNarroFiles->MetaAddColumn('FilePath');
     $this->dtgNarroFiles->MetaAddColumn('FileMd5');
     $this->dtgNarroFiles->MetaAddColumn(QQN::NarroFile()->Parent);
     $this->dtgNarroFiles->MetaAddTypeColumn('TypeId', 'NarroFileType');
     $this->dtgNarroFiles->MetaAddColumn(QQN::NarroFile()->Project);
     $this->dtgNarroFiles->MetaAddColumn('Active');
     $this->dtgNarroFiles->MetaAddColumn('Created');
     $this->dtgNarroFiles->MetaAddColumn('Modified');
     $this->dtgNarroFiles->MetaAddColumn('Header');
 }
Example #8
0
 function validate($data, &$failed = null)
 {
     $ret = parent::validate($data);
     if ($this->has_file) {
         try {
             $errors = array();
             foreach ($_FILES as $k => $v) {
                 if (isset($v['error']) && $v['error'] == UPLOAD_ERR_NO_FILE) {
                     if ($this->must) {
                         $errors[] = '请选择上传文件!';
                         break;
                     }
                     continue;
                 }
                 $fileExt = Helper_Upload::fileExt($v['name']);
                 if (!in_array(strtolower($fileExt), Helper_Upload::getTypes())) {
                     $errors[] = '上传文件的类型不符合要求';
                 }
                 if ($v['size'] > Helper_Upload::getSize()) {
                     $errors[] = '上传文件的大小超过限制';
                 }
             }
             if (empty($errors)) {
                 return $ret;
             }
             $this[$this->has_file]->invalidate(implode(', ', $errors));
             return false;
         } catch (Exception $ex) {
             $this[$this->has_file]->invalidate($ex->getMessage());
             return false;
         }
     } else {
         return $ret;
     }
 }
Example #9
0
 function validate($data, &$failed = null)
 {
     $ret = parent::validate($data);
     $id = $this->_upload_element->id;
     $uploader = new Helper_Uploader();
     try {
         if (!$uploader->existsFile($id)) {
             if ($this->_skip_upload_enabled) {
                 return $ret;
             }
             throw new QException('没有正确上传文件');
         }
         $file = $uploader->file($id);
         $errors = array();
         if (!$file->isValid($this->_upload_allowed_types)) {
             $errors[] = '上传文件的类型不符合要求';
         }
         if ($file->filesize() > $this->_upload_allowed_size) {
             $errors[] = '上传文件的大小超过限制';
         }
         if (empty($errors)) {
             $this->_upload_element->value = $file;
             return $ret;
         }
         $failed[] = $id;
         $this->_upload_element->invalidate(implode(', ', $errors));
         return false;
     } catch (Exception $ex) {
         $this->_upload_element->invalidate($ex->getMessage());
         return false;
     }
 }
 protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroSuggestions = new NarroSuggestionDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroSuggestions->CssClass = 'datagrid';
     $this->dtgNarroSuggestions->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroSuggestions->Paginator = new QPaginator($this->dtgNarroSuggestions);
     $this->dtgNarroSuggestions->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_suggestion_edit.php';
     $this->dtgNarroSuggestions->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_suggestion's properties, or you
     // can traverse down QQN::narro_suggestion() to display fields that are down the hierarchy)
     $this->dtgNarroSuggestions->MetaAddColumn('SuggestionId');
     $this->dtgNarroSuggestions->MetaAddColumn(QQN::NarroSuggestion()->User);
     $this->dtgNarroSuggestions->MetaAddColumn(QQN::NarroSuggestion()->Text);
     $this->dtgNarroSuggestions->MetaAddColumn(QQN::NarroSuggestion()->Language);
     $this->dtgNarroSuggestions->MetaAddColumn('SuggestionValue');
     $this->dtgNarroSuggestions->MetaAddColumn('SuggestionValueMd5');
     $this->dtgNarroSuggestions->MetaAddColumn('SuggestionCharCount');
     $this->dtgNarroSuggestions->MetaAddColumn('SuggestionWordCount');
     $this->dtgNarroSuggestions->MetaAddColumn('HasComments');
     $this->dtgNarroSuggestions->MetaAddColumn('IsImported');
     $this->dtgNarroSuggestions->MetaAddColumn('Created');
     $this->dtgNarroSuggestions->MetaAddColumn('Modified');
 }
 protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroContextInfos = new NarroContextInfoDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroContextInfos->CssClass = 'datagrid';
     $this->dtgNarroContextInfos->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroContextInfos->Paginator = new QPaginator($this->dtgNarroContextInfos);
     $this->dtgNarroContextInfos->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_context_info_edit.php';
     $this->dtgNarroContextInfos->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_context_info's properties, or you
     // can traverse down QQN::narro_context_info() to display fields that are down the hierarchy)
     $this->dtgNarroContextInfos->MetaAddColumn('ContextInfoId');
     $this->dtgNarroContextInfos->MetaAddColumn(QQN::NarroContextInfo()->Context);
     $this->dtgNarroContextInfos->MetaAddColumn(QQN::NarroContextInfo()->Language);
     $this->dtgNarroContextInfos->MetaAddColumn(QQN::NarroContextInfo()->ValidatorUser);
     $this->dtgNarroContextInfos->MetaAddColumn(QQN::NarroContextInfo()->ValidSuggestion);
     $this->dtgNarroContextInfos->MetaAddColumn('HasSuggestions');
     $this->dtgNarroContextInfos->MetaAddColumn('SuggestionAccessKey');
     $this->dtgNarroContextInfos->MetaAddColumn('SuggestionCommandKey');
     $this->dtgNarroContextInfos->MetaAddColumn('Created');
     $this->dtgNarroContextInfos->MetaAddColumn('Modified');
 }
Example #12
0
 function __construct($action)
 {
     // 调用父类的构造函数
     parent::__construct("form1", $action);
     // 从配置文件载入表单
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . 'user_form.yaml';
     $this->loadFromConfig(Helper_YAML::loadCached($filename));
     // 添加表单验证
     //$this->addValidations(Users::meta());
 }
		public function __construct(QForm $objForm, $strGroupingId) {
			if (strlen($strGroupingId) == 0)
				$this->strGroupingId = $objForm->GenerateControlId();
			else {
				// Verify ControlId is only AlphaNumeric Characters
				$strMatches = array();
				$strPattern = '/[A-Za-z0-9]*/';
				preg_match($strPattern, $strGroupingId, $strMatches);
				if (count($strMatches) && ($strMatches[0] == $strGroupingId))
					$this->strGroupingId = $strGroupingId;
				else
					throw new QCallerException('GroupingIDs must be only alphanumeric chacters: ' . $strGroupingId);
			}
			try {
				$objForm->AddGrouping($this);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
Example #14
0
 function __construct($action)
 {
     // 调用父类的构造函数
     parent::__construct("form_changepassword", $action);
     // 从配置文件载入表单
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . 'changepassword_form.yaml';
     $this->loadFromConfig(Helper_YAML::loadCached($filename));
     $this['old_password']->addValidations(array($this, 'checkPasswordLen'), '密码长度只能在4-32位之间');
     $this['new_password']->addValidations(array($this, 'checkPasswordLen'), '密码长度只能在4-32位之间');
     $this['new_password2']->addValidations(array($this, 'checkSecPasswd'), '两次输入的密码必须一致');
     //$this->addValidations(Users::meta());
 }
Example #15
0
 function testElements()
 {
     $form = new QForm('form1', self::URL1);
     $form->add(QForm::ELEMENT, 'username', array('_ui' => 'textbox', 'maxlength' => 15, 'class' => 'input'))->add(QForm::ELEMENT, 'password', array('_ui' => 'password', 'class' => 'input'));
     $this->assertTrue($form->existsElement('username'));
     $this->assertTrue($form->existsElement('password'));
     $this->assertEquals('textbox', $form->element('username')->_ui);
     $this->assertEquals('password', $form->element('password')->_ui);
     $form->remove('password');
     $this->assertFalse($form->existsElement('password'));
     $attrs = $form['username']->attrs();
     $this->assertEquals(array('id' => 'username', 'name' => 'username', 'maxlength' => 15, 'class' => 'input'), $attrs);
     $all_attrs = $form['username']->allAttrs();
     $this->assertEquals(array('id' => 'username', 'name' => 'username', 'maxlength' => 15, 'class' => 'input', '_ui' => 'textbox', '_data_binding' => true, '_nested_name' => 'form1'), $all_attrs);
     unset($form['username']);
     $this->assertFalse($form->existsElement('username'));
     $this->assertFalse(isset($form['username']));
 }
Example #16
0
 function __construct($action)
 {
     parent::__construct('post_form', $action);
     // 输入框
     $props = array('class' => 'textbox', 'max_length' => 85);
     $this->add(new QForm_Element('title', 'textbox', $props))->set('label', '文章标题')->set('description', '');
     $props = array('class' => 'textbox', 'rows' => 20);
     $this->add(new QForm_Element('body', 'memo', $props))->set('label', '文章内容')->set('description', '可以使用 BBCode 格式化内容');
     $props = array('class' => 'textbox', 'max_length' => 60);
     $this->add(new QForm_Element('tags', 'textbox', $props))->set('label', '标签')->set('description', '多个类别间请用空格分隔')->onSetValue(array($this, 'setTags'));
     $props = array('caption' => '保存修改');
     $this->add(new QForm_Element('save', 'submit', $props));
     $this->loadValidationsFromModel('Post');
 }
 /**
  * This Form_Validate event handler allows you to specify any custom Form Validation rules.
  * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
  */
 protected function Form_Validate()
 {
     // By default, we report the result of validation from the parent
     $blnToReturn = parent::Form_Validate();
     // Custom Validation Rules
     // TODO: Be sure to set $blnToReturn to false if any custom validation fails!
     $blnFocused = false;
     foreach ($this->GetErrorControls() as $objControl) {
         // Set Focus to the top-most invalid control
         if (!$blnFocused) {
             $objControl->Focus();
             $blnFocused = true;
         }
         // Blink on ALL invalid controls
         $objControl->Blink();
     }
     return $blnToReturn;
 }
 /**
  * 编辑解决方案
  *
  */
 function actionEdit()
 {
     //创建表单
     $form = new QForm('solution', url('solutions/edit'));
     $form->add(QForm::ELEMENT, 'id', array('_ui' => 'hidden'))->add(QForm::ELEMENT, 'name', array('_ui' => 'textbox', '_label' => '解决方案名'))->add(QForm::ELEMENT, 'content', array('_ui' => 'fckeditor', '_label' => '内容', 'class' => "txt", 'height' => '500px', 'width' => '60%'));
     $form->addValidations(Solution::meta());
     $solu_id = (int) $this->_context->id;
     $data = Solution::find($solu_id)->query();
     //导入数据
     $form->import($data);
     if ($this->_context->isPOST() && $form->invalidate($_POST)) {
         try {
             $data->changeProps($form->values());
             $data->save();
             return $this->_redirectMessage('修改成功', '修改改页面成功', url('solutions/index'));
         } catch (QValidator_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     }
     $this->_view['form'] = $form;
 }
 /**
  * This Form_Validate event handler allows you to specify any custom Form Validation rules.
  * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
  */
 protected function Form_Validate()
 {
     // By default, we report the result of validation from the parent
     $blnToReturn = parent::Form_Validate();
     // Custom Validation Rules
     // TODO: Be sure to set $blnToReturn to false if any custom validation fails!
     // Check for records that may violate Unique Clauses
     if (($objNarroPermission = NarroPermission::LoadByPermissionName($this->txtPermissionName->Text)) && $objNarroPermission->PermissionId != $this->mctNarroPermission->NarroPermission->PermissionId) {
         $blnToReturn = false;
         $this->txtPermissionName->Warning = QApplication::Translate("Already in Use");
     }
     $blnFocused = false;
     foreach ($this->GetErrorControls() as $objControl) {
         // Set Focus to the top-most invalid control
         if (!$blnFocused) {
             $objControl->Focus();
             $blnFocused = true;
         }
         // Blink on ALL invalid controls
         $objControl->Blink();
     }
     return $blnToReturn;
 }
 protected function Form_Create()
 {
     parent::Form_Create();
     // Instantiate the Meta DataGrid
     $this->dtgNarroContextComments = new NarroContextCommentDataGrid($this);
     // Style the DataGrid (if desired)
     $this->dtgNarroContextComments->CssClass = 'datagrid';
     $this->dtgNarroContextComments->AlternateRowStyle->CssClass = 'alternate';
     // Add Pagination (if desired)
     $this->dtgNarroContextComments->Paginator = new QPaginator($this->dtgNarroContextComments);
     $this->dtgNarroContextComments->ItemsPerPage = 20;
     // Use the MetaDataGrid functionality to add Columns for this datagrid
     // Create an Edit Column
     $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_context_comment_edit.php';
     $this->dtgNarroContextComments->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit');
     // Create the Other Columns (note that you can use strings for narro_context_comment's properties, or you
     // can traverse down QQN::narro_context_comment() to display fields that are down the hierarchy)
     $this->dtgNarroContextComments->MetaAddColumn('CommentId');
     $this->dtgNarroContextComments->MetaAddColumn(QQN::NarroContextComment()->Context);
     $this->dtgNarroContextComments->MetaAddColumn('Created');
     $this->dtgNarroContextComments->MetaAddColumn('Modified');
     $this->dtgNarroContextComments->MetaAddColumn('CommentText');
     $this->dtgNarroContextComments->MetaAddColumn('CommentTextMd5');
 }
Example #21
0
 protected function lstTramorField_Change($strFormId, $strControlId, $strParameter)
 {
     $objControl = QForm::GetControl($strControlId);
     if ($objControl->SelectedValue != null) {
         $search = strtolower($objControl->SelectedValue);
         if ($this->in_array_nocase($search, $this->arrTracmorField)) {
             $objControl->Warning = "This value has already been selected.";
             $objControl->SelectedIndex = 0;
             unset($this->arrTracmorField[substr($objControl->Name, 3)]);
         } else {
             $objControl->Warning = "";
             $txtDefault = $this->txtMapDefaultValueArray[substr($objControl->Name, 3)];
             $lstDefault = $this->lstMapDefaultValueArray[substr($objControl->Name, 3)];
             $dtpDefault = $this->dtpDateArray[substr($objControl->Name, 3)];
             $this->arrTracmorField[substr($objControl->Name, 3)] = $search;
             if (substr($objControl->SelectedValue, 0, 8) == "contact_") {
                 $objCustomField = CustomField::LoadByCustomFieldId(substr($objControl->SelectedValue, 8));
                 // type = Text or TextBox
                 if ($objCustomField->CustomFieldQtypeId != 2) {
                     $txtDefault->Required = $objCustomField->RequiredFlag;
                     // If it is a required text field, then assign the default text for a new entity only
                     if ($objCustomField->RequiredFlag && $objCustomField->DefaultCustomFieldValueId) {
                         $txtDefault->Text = $objCustomField->DefaultCustomFieldValue->ShortDescription;
                     } else {
                         $txtDefault->Text = "";
                     }
                     $txtDefault->Display = true;
                     $lstDefault->Display = false;
                     $dtpDefault->Display = false;
                 } else {
                     $lstDefault->RemoveAllItems();
                     $lstDefault->AddItem('- Select One -', null);
                     $lstDefault->Required = true;
                     $objCustomFieldValueArray = CustomFieldValue::LoadArrayByCustomFieldId(substr($objControl->SelectedValue, 8), QQ::Clause(QQ::OrderBy(QQN::CustomFieldValue()->ShortDescription)));
                     if ($objCustomFieldValueArray) {
                         foreach ($objCustomFieldValueArray as $objCustomFieldValue) {
                             $objListItem = new QListItem($objCustomFieldValue->__toString(), $objCustomFieldValue->CustomFieldValueId);
                             // If it is a required field, then select the value on new entities by default
                             if ($objCustomField->RequiredFlag && $objCustomField->DefaultCustomFieldValueId && $objCustomField->DefaultCustomFieldValueId == $objCustomFieldValue->CustomFieldValueId) {
                                 $objListItem->Selected = true;
                             }
                             $lstDefault->AddItem($objListItem);
                         }
                     }
                     $txtDefault->Display = false;
                     $lstDefault->Display = true;
                     $dtpDefault->Display = false;
                 }
             }
             $txtDefault->Display = true;
             $lstDefault->Display = false;
             $dtpDefault->Display = false;
         }
     } else {
         unset($this->arrTracmorField[substr($objControl->Name, 3)]);
     }
 }
Example #22
0
<?php

require dirname(__FILE__) . '/../_require_prepend.inc.php';
require __INCLUDES__ . '/examples/examples.inc.php';
QForm::$FormStateHandler = 'QSessionFormStateHandler';
class ExampleForm extends ExamplesBaseForm
{
    protected $tnvExample;
    protected $pnlCode;
    // Define all the QContrtol objects for our Calculator
    // Make our textboxes IntegerTextboxes and make them required
    protected function Form_Create()
    {
        $this->tnvExample = new QTreeNav($this);
        $this->tnvExample->CssClass = 'treenav';
        $this->tnvExample->AddAction(new QChangeEvent(), new QAjaxAction('tnvExample_Change'));
        $this->pnlCode = new QPanel($this);
        $this->pnlCode->CssClass = 'codeDisplay';
        $this->objDefaultWaitIcon = new QWaitIcon($this);
        // Create a treenav of the file/folder directory for qcodo includes
        $this->tnvExample_AddItems(dirname(__INCLUDES__ . '.'));
    }
    protected function tnvExample_AddItems($strDirectory, $objParentItem = null)
    {
        $objDirectory = opendir($strDirectory);
        if (!$objParentItem) {
            $objParentItem = $this->tnvExample;
        }
        while ($strFilename = readdir($objDirectory)) {
            if ($strFilename && $strFilename != '.' && $strFilename != '..' && $strFilename != 'configuration.inc.php' && $strFilename != 'configuration_pro.inc.php' && $strFilename != 'CVS') {
                // Create the new TreeNavItem
Example #23
0
<?php

require '../../includes/prepend.inc.php';
// First of all, let's override the way QForm stores state information.
// We will use the session-based FormState Handler, instead of the standard/default
// formstate handler.  Also, let's encrypt the formstate index by defining
// an encryption key.
//
// NOTE: This preference can be set, globally, by updating the QForm class
// which is located at /includes/qform/QForm.inc
QForm::$FormStateHandler = 'QSessionFormStateHandler';
QForm::$EncryptionKey = '\\rSome.Random!Key\\0';
// Everything else below should be the exact same as our original Hello, World! example
class ExampleForm extends QForm
{
    // Local declarations of our Qcontrols
    protected $lblMessage;
    protected $btnButton;
    // Initialize our Controls during the Form Creation process
    protected function Form_Create()
    {
        // Define the Label
        $this->lblMessage = new QLabel($this);
        $this->lblMessage->Text = 'Click the button to change my message.';
        // Define the Button
        $this->btnButton = new QButton($this);
        $this->btnButton->Text = 'Click Me!';
        // Add a Click event handler to the button
        $this->btnButton->AddAction(new QClickEvent(), new QServerAction('btnButton_Click'));
    }
    // The "btnButton_Click" Event handler
Example #24
0
     * on the HTML page, then you need to add "foo.js" to this IgnoreJavaScriptFileArray so that Qcodo
     * doesn't try and also load "foo.js" for you. 
     * 
     * NOTE: In production or as a performance tweak, you may want to use the compressed "_qc_packed.js"
     * library (which is a compressed, single file version of ALL the qcodo .js files that is in _core).
     * 
     * If you want to do this, MAKE SURE you FIRST MANUALLY do a <script> inclusion of
     * "/assets/js/_core/_qc_packed.js" in your HTML.  Then, you can specify that QForm "ignore" all the
     * other qcodo _core javascripts by adding just "_core" to the array.
     *
     * @var array
     */
    //		protected $strIgnoreJavaScriptFileArray = array();
    protected $strIgnoreJavaScriptFileArray = array('_core');
    /**
     * This should be very rarely used.
     * 
     * This mechanism acts similarly to the strIgnoreJavascriptFileArray, except it applies to StyleSheets.
     * However, any QControl that specifies a StyleSheet file to include is MEANT to have that property be modified / customized.
     * 
     * Therefore, there should be little to no need for this attribute.  However, it is here anyway, just in case.
     *
     * @var array
     */
    protected $strIgnoreStyleSheetFileArray = array();
}
// For NOAH in Production, let's use FileFormStateHandler
if (array_key_exists('HTTP_HOST', $_SERVER) && strpos($_SERVER['HTTP_HOST'], 'noah') !== false) {
    QForm::$FormStateHandler = 'QFileFormStateHandler';
    QFileFormStateHandler::$GarbageCollectDaysOld = 1;
}
    /**
     * Renders the end of the form, including the closing form and body tags.
     * Renders the html for hidden controls.
     * @param bool $blnDisplayOutput should the output be returned or directly printed to screen.
     *
     * @return null|string
     * @throws QCallerException
     */
    public function RenderEnd($blnDisplayOutput = true)
    {
        // Ensure that RenderEnd() has not yet been called
        switch ($this->intFormStatus) {
            case QFormBase::FormStatusUnrendered:
                throw new QCallerException('$this->RenderBegin() was never called');
            case QFormBase::FormStatusRenderBegun:
                break;
            case QFormBase::FormStatusRenderEnded:
                throw new QCallerException('$this->RenderEnd() has already been called');
                break;
            default:
                throw new QCallerException('FormStatus is in an unknown status');
        }
        $strHtml = '';
        // This will be the final output
        /**** Render any controls that get automatically rendered ****/
        foreach ($this->GetAllControls() as $objControl) {
            if ($objControl->AutoRender && !$objControl->Rendered) {
                $strRenderMethod = $objControl->PreferredRenderMethod;
                $strHtml .= $objControl->{$strRenderMethod}(false) . _nl();
            }
        }
        /**** Prepare Javascripts ****/
        // Clear included javascript array since we are completely redrawing the page
        $this->strIncludedJavaScriptFileArray = array();
        $strControlIdToRegister = array();
        $strEventScripts = '';
        // Add form level javascripts and libraries
        $strJavaScriptArray = $this->ProcessJavaScriptList($this->GetFormJavaScripts());
        QApplication::AddJavaScriptFiles($strJavaScriptArray);
        $strFormJsFiles = QApplication::RenderFiles();
        // Render the form-level javascript files separately
        // Go through all controls and gather up any JS or CSS to run or Form Attributes to modify
        foreach ($this->GetAllControls() as $objControl) {
            if ($objControl->Rendered || $objControl->ScriptsOnly) {
                $strControlIdToRegister[] = $objControl->ControlId;
                /* Note: GetEndScript may cause the control to register additional commands, or even add javascripts, so those should be handled after this. */
                if ($strControlScript = $objControl->GetEndScript()) {
                    $strControlScript = JavaScriptHelper::TerminateScript($strControlScript);
                    // Add comments for developer version of output
                    if (!QApplication::$Minimize) {
                        // Render a comment
                        $strControlScript = _nl() . _nl() . sprintf('/*** EndScript -- Control Type: %s, Control Name: %s, Control Id: %s  ***/', get_class($objControl), $objControl->Name, $objControl->ControlId) . _nl() . _indent($strControlScript);
                    }
                    $strEventScripts .= $strControlScript;
                }
            }
            // Include the javascripts specified by each control.
            if ($strScriptArray = $this->ProcessJavaScriptList($objControl->JavaScripts)) {
                QApplication::AddJavaScriptFiles($strScriptArray);
            }
            // Include any StyleSheets?  The control would have a
            // comma-delimited list of stylesheet files to include (if applicable)
            if ($strScriptArray = $this->ProcessStyleSheetList($objControl->StyleSheets)) {
                QApplication::AddStyleSheets(array_keys($strScriptArray));
            }
            // Form Attributes?
            if ($objControl->FormAttributes) {
                QApplication::ExecuteControlCommand($this->strFormId, 'attr', $objControl->FormAttributes);
                foreach ($objControl->FormAttributes as $strKey => $strValue) {
                    if (!array_key_exists($strKey, $this->strFormAttributeArray)) {
                        $this->strFormAttributeArray[$strKey] = $strValue;
                    } else {
                        if ($this->strFormAttributeArray[$strKey] != $strValue) {
                            $this->strFormAttributeArray[$strKey] = $strValue;
                        }
                    }
                }
            }
        }
        // Add grouping commands to events (Used for deprecated drag and drop, but not removed yet)
        foreach ($this->objGroupingArray as $objGrouping) {
            $strGroupingScript = $objGrouping->Render();
            if (strlen($strGroupingScript) > 0) {
                $strGroupingScript = JavaScriptHelper::TerminateScript($strGroupingScript);
                $strEventScripts .= $strGroupingScript;
            }
        }
        /*** Build the javascript block ****/
        // Start with variable settings and initForm
        $strEndScript = sprintf('qc.initForm("%s"); ', $this->strFormId);
        // Register controls
        if ($strControlIdToRegister) {
            $strEndScript .= sprintf("qc.regCA(%s); \n", JavaScriptHelper::toJsObject($strControlIdToRegister));
        }
        // Design mode event
        if (defined('__DESIGN_MODE__') && __DESIGN_MODE__ == 1) {
            // attach an event listener to the form to send context menu selections to the designer dialog for processing
            $strEndScript .= sprintf('$j("#%s").on("contextmenu", "[id]", 
						function(event) {
							$j("#qconnectoreditdlg").trigger("qdesignerclick", 
								[{id: event.target.id ? event.target.id : $j(event.target).parents("[id]").attr("id"), for: $j(event.target).attr("for")}]
							);
							return false;
						}
					);', $this->FormId);
        }
        // Add any application level js commands.
        // This will include high and medimum level commands
        $strEndScript .= QApplication::RenderJavascript(true);
        // Add the javascript coming from controls and events just after the medium level commands
        $strEndScript .= ';' . $strEventScripts;
        // Add low level commands and other things that need to execute at the end
        $strEndScript .= ';' . QApplication::RenderJavascript(false);
        // Create Final EndScript Script
        $strEndScript = sprintf('<script type="text/javascript">$j(document).ready(function() { %s; });</script>', $strEndScript);
        /**** Render the HTML itself, appending the javascript we generated above ****/
        foreach ($this->GetAllControls() as $objControl) {
            if ($objControl->Rendered) {
                $strHtml .= $objControl->GetEndHtml();
            }
            $objControl->ResetFlags();
            // Make sure controls are serialized in a reset state
        }
        $strHtml .= $strFormJsFiles . _nl();
        // Add form level javascript files
        // put javascript environment defines up early for use by other js files.
        $strHtml .= '<script type="text/javascript">' . sprintf('qc.baseDir = "%s"; ', __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__) . sprintf('qc.jsAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __JS_ASSETS__) . sprintf('qc.phpAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __PHP_ASSETS__) . sprintf('qc.cssAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __CSS_ASSETS__) . sprintf('qc.imageAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __IMAGE_ASSETS__) . '</script>' . _nl();
        $strHtml .= QApplication::RenderFiles() . _nl();
        // add plugin and control js files
        // Render hidden controls related to the form
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormId" id="Qform__FormId" value="%s" />', $this->strFormId) . _nl();
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormControl" id="Qform__FormControl" value="" />') . _nl();
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormEvent" id="Qform__FormEvent" value="" />') . _nl();
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormParameter" id="Qform__FormParameter" value="" />') . _nl();
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormCallType" id="Qform__FormCallType" value="" />') . _nl();
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormUpdates" id="Qform__FormUpdates" value="" />') . _nl();
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormCheckableControls" id="Qform__FormCheckableControls" value="" />') . _nl();
        // Serialize and write out the formstate
        $strHtml .= sprintf('<input type="hidden" name="Qform__FormState" id="Qform__FormState" value="%s" />', QForm::Serialize(clone $this)) . _nl();
        // close the form tag
        $strHtml .= "</form>";
        // Add the JavaScripts rendered above
        $strHtml .= $strEndScript;
        // close the body tag
        if ($this->blnRenderedBodyTag) {
            $strHtml .= '</body>';
        }
        /**** Cleanup ****/
        // Update Form Status
        $this->intFormStatus = QFormBase::FormStatusRenderEnded;
        // Display or Return
        if ($blnDisplayOutput) {
            if (!QApplication::$CliMode) {
                print $strHtml;
            }
            return null;
        } else {
            if (!QApplication::$CliMode) {
                return $strHtml;
            } else {
                return '';
            }
        }
    }
Example #26
0
 /**
  * @param bool $blnDisplayOutput should the output be returned or directly printed to screen.
  *
  * @return null|string
  * @throws QCallerException
  */
 public function RenderEnd($blnDisplayOutput = true)
 {
     // Ensure that RenderEnd() has not yet been called
     switch ($this->intFormStatus) {
         case QFormBase::FormStatusUnrendered:
             throw new QCallerException('$this->RenderBegin() was never called');
         case QFormBase::FormStatusRenderBegun:
             break;
         case QFormBase::FormStatusRenderEnded:
             throw new QCallerException('$this->RenderEnd() has already been called');
             break;
         default:
             throw new QCallerException('FormStatus is in an unknown status');
     }
     //Clear included javascript array
     $this->strIncludedJavaScriptFileArray = array();
     // Setup End Script
     $strEndScript = '';
     $strEvents = '';
     // First, call regC on all Controls
     $strControlIdToRegister = array();
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             array_push($strControlIdToRegister, '"' . $objControl->ControlId . '"');
         }
     }
     if (count($strControlIdToRegister)) {
         $strEndScript .= sprintf('qc.regCA(new Array(%s)); ', implode(',', $strControlIdToRegister));
     }
     // Next, run any GetEndScrips on Controls and Groupings
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             $strControlScript = $objControl->GetEndScript();
             if (strlen($strControlScript) > 0) {
                 $strEvents .= $strControlScript . ";\n";
             }
         }
     }
     foreach ($this->objGroupingArray as $objGrouping) {
         $strGroupingScript = $objGrouping->Render();
         if (strlen($strGroupingScript) > 0) {
             $strEvents .= $strGroupingScript . ";\n";
         }
     }
     // Run End Script Compressor
     $strEndScriptArray = explode(";\n", $strEndScript);
     $strEndScriptCommands = array();
     foreach ($strEndScriptArray as $strEndScript) {
         $strEndScriptCommands[trim($strEndScript)] = true;
     }
     $strEndScript = implode(";\n", array_keys($strEndScriptCommands));
     // Next, go through all controls and gather up any JS or CSS to run or Form Attributes to modify
     // due to dynamically created controls
     $strJavaScriptToAddArray = array();
     $strStyleSheetToAddArray = array();
     $strFormAttributeToModifyArray = array();
     foreach ($this->GetAllControls() as $objControl) {
         // Include any JavaScripts?  The control would have a
         // comma-delimited list of javascript files to include (if applicable)
         if ($strScriptArray = $this->ProcessJavaScriptList($objControl->JavaScripts)) {
             $strJavaScriptToAddArray = array_merge($strJavaScriptToAddArray, $strScriptArray);
         }
         // Include any StyleSheets?  The control would have a
         // comma-delimited list of stylesheet files to include (if applicable)
         if ($strScriptArray = $this->ProcessStyleSheetList($objControl->StyleSheets)) {
             $strStyleSheetToAddArray = array_merge($strStyleSheetToAddArray, $strScriptArray);
         }
         // Form Attributes?
         if ($objControl->FormAttributes) {
             foreach ($objControl->FormAttributes as $strKey => $strValue) {
                 if (!array_key_exists($strKey, $this->strFormAttributeArray)) {
                     $this->strFormAttributeArray[$strKey] = $strValue;
                     $strFormAttributeToModifyArray[$strKey] = $strValue;
                 } else {
                     if ($this->strFormAttributeArray[$strKey] != $strValue) {
                         $this->strFormAttributeArray[$strKey] = $strValue;
                         $strFormAttributeToModifyArray[$strKey] = $strValue;
                     }
                 }
             }
         }
     }
     // Figure out initial list of JavaScriptIncludes
     $strJavaScriptArray = $this->ProcessJavaScriptList(__JQUERY_BASE__ . ', ' . __JQUERY_EFFECTS__ . ',jquery/jquery.ajaxq-0.0.1.js,' . __QCUBED_JS_CORE__);
     if (defined('__PRELOAD_JS_FILES__') && __PRELOAD_JS_FILES__) {
         $strJavaScriptArray = array_merge($strJavaScriptArray, $strJavaScriptToAddArray);
         $strJavaScriptToAddArray = array();
     }
     // Setup IncludeJs
     $strToReturn = "\r\n";
     // Include javascripts that need to be included
     foreach ($strJavaScriptArray as $strScript) {
         $strToReturn .= sprintf('<script type="text/javascript" src="%s"></script>', $this->GetJsFileUri($strScript));
         $strToReturn .= "\r\n";
     }
     // First, alter any <Form> settings that need to be altered
     foreach ($strFormAttributeToModifyArray as $strKey => $strValue) {
         $strEndScript .= sprintf('document.getElementById("%s").%s = "%s"; ', $this->strFormId, $strKey, $strValue);
     }
     // Next, add any new CSS files that haven't yet been included to the end of the High Priority commands string
     foreach ($strStyleSheetToAddArray as $strScript) {
         $strEndScript .= 'qc.loadStyleSheetFile("' . $strScript . '", "all"); ';
     }
     if ($strEvents) {
         // qc.regCA first, $strEvents 2nd, application scripts 3rd
         $strEndScript = $strEndScript . ';' . $strEvents;
     }
     // Add any application level js commands. These might refer to previous objects.
     $strEndScript .= QApplication::RenderJavaScript(false);
     // Next, add any new JS files that haven't yet been included to the BEGINNING of the High Priority commands string
     // (already rendered HP commands up to this point will be placed into the callback)
     foreach (array_reverse($strJavaScriptToAddArray) as $strScript) {
         if ($strEndScript) {
             $strEndScript = 'qc.loadJavaScriptFile("' . $strScript . '", function() {' . $strEndScript . '}); ';
         } else {
             $strEndScript = 'qc.loadJavaScriptFile("' . $strScript . '", null); ';
         }
     }
     // Finally, add QCubed includes path
     $strEndScript = sprintf('qc.baseDir = "%s"; ', __VIRTUAL_DIRECTORY__) . $strEndScript;
     $strEndScript = sprintf('qc.jsAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __JS_ASSETS__) . $strEndScript;
     $strEndScript = sprintf('qc.phpAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __PHP_ASSETS__) . $strEndScript;
     $strEndScript = sprintf('qc.cssAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __CSS_ASSETS__) . $strEndScript;
     $strEndScript = sprintf('qc.imageAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __IMAGE_ASSETS__) . $strEndScript;
     // Create Final EndScript Script
     $strEndScript = sprintf('<script type="text/javascript">$j(document).ready(function() { %s; });</script>', $strEndScript);
     // Persist Controls (if applicable)
     foreach ($this->objPersistentControlArray as $objControl) {
         $objControl->Persist();
     }
     // Clone Myself
     $objForm = clone $this;
     // Render HTML
     $strToReturn .= "\r\n<div style=\"display: none;\">\r\n\t";
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormState" id="Qform__FormState" value="%s" />', QForm::Serialize($objForm));
     $strToReturn .= "\r\n\t";
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormId" id="Qform__FormId" value="%s" />', $this->strFormId);
     $strToReturn .= "\r\n</div>\r\n";
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormControl" id="Qform__FormControl" value="" />');
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormEvent" id="Qform__FormEvent" value="" />');
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormParameter" id="Qform__FormParameter" value="" />');
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormCallType" id="Qform__FormCallType" value="" />');
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormUpdates" id="Qform__FormUpdates" value="" />');
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormCheckableControls" id="Qform__FormCheckableControls" value="" />');
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             $strToReturn .= $objControl->GetEndHtml();
         }
     }
     $strToReturn .= "\n</form>";
     $strToReturn .= $strEndScript;
     if ($this->blnRenderedBodyTag) {
         $strToReturn .= '</body>';
     }
     // Update Form Status
     $this->intFormStatus = QFormBase::FormStatusRenderEnded;
     // Display or Return
     if ($blnDisplayOutput) {
         if (!QApplication::$CliMode) {
             print $strToReturn;
         }
         return null;
     } else {
         if (!QApplication::$CliMode) {
             return $strToReturn;
         } else {
             return '';
         }
     }
 }
Example #27
0
    if (!isset($_GET['form']) or !$_GET['form'] or strpos($_GET['form'], '..') or strpos($_GET['form'], '/')) {
        $_GET['form'] = Security::Current() ? Security::Current()->Role == Role::Buyer ? 'BuyersNewsForm' : 'SellersNewsForm' : 'MainForm';
    }
    // we have to be a bit ugly here - using qcodo for each hint-request causes unserializing of all objects - f***s performance too much
    if ($_GET['form'] == 'Special') {
        file_put_contents("/tmp/dump", "hej", FILE_APPEND);
        //$ret = call_user_func(array($_GET['arg1'], $_GET['arg2']));
        die("test\n");
    }
    // Load up the form (we have to load it manually, since class_exists doesn't autoload)
    QApplication::Autoload($_GET['form']);
    if (!class_exists($_GET['form'])) {
        throw new NoSuchFormException(QApplication::Translate("Oqtopus knows no form named") . " " . $_GET['form']);
    }
    QApplication::$FormName = $_GET['form'];
    QForm::Run($_GET['form'], sprintf('%s%s.inc', __TEMPLATES__, $_GET['form']));
} catch (AccessDeniedException $e) {
    Navigation::Home();
} catch (QMySqliDatabaseException $e) {
    if (SERVER_INSTANCE == 'prod' || SERVER_INSTACE == 'demo') {
        die("It seems like we're having some problems with the database right now.. Please try again in a bunch!");
    } else {
        throw $e;
    }
} catch (NoSuchFormException $e) {
    die("I don't know no form with that name!");
} catch (NoSuchObjectException $e) {
    if (SERVER_INSTANCE == 'prod' || SERVER_INSTANCE == 'demo') {
        Navigation::Home();
    } else {
        throw $e;
Example #28
0
            }
        }
    }
    //////////////////////////////////////////////
    // Setup Internationalization and Localization (if applicable)
    // Note, this is where you would implement code to do Language Setting discovery, as well, for example:
    // * Checking against $_GET['language_code']
    // * checking against session (example provided below)
    // * Checking the URL
    // * etc.
    // TODO: options to do this are left to the developer
    //////////////////////////////////////////////
    if (isset($_SESSION)) {
        if (array_key_exists('country_code', $_SESSION)) {
            QApplication::$CountryCode = $_SESSION['country_code'];
        }
        if (array_key_exists('language_code', $_SESSION)) {
            QApplication::$LanguageCode = $_SESSION['language_code'];
        }
    }
    // Initialize I18n if QApplication::$LanguageCode is set
    if (QApplication::$LanguageCode) {
        QI18n::Initialize();
    } else {
        // QApplication::$CountryCode = 'us';
        // QApplication::$LanguageCode = 'en';
        // QI18n::Initialize();
    }
    QForm::$FormStateHandler = 'QFileFormStateHandler';
    QForm::$EncryptionKey = 'gogogadgetQcodoAPI';
}
Example #29
0
 protected function RenderEnd($blnDisplayOutput = true)
 {
     // Ensure that RenderEnd() has not yet been called
     switch ($this->intFormStatus) {
         case QFormBase::FormStatusUnrendered:
             throw new QCallerException('$this->RenderBegin() was never called');
         case QFormBase::FormStatusRenderBegun:
             break;
         case QFormBase::FormStatusRenderEnded:
             throw new QCallerException('$this->RenderEnd() has already been called');
             break;
         default:
             throw new QCallerException('FormStatus is in an unknown status');
     }
     // Setup End Script
     $strEndScript = '';
     // First, call regC on all Controls
     $strControlIdToRegister = array();
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             array_push($strControlIdToRegister, '"' . $objControl->ControlId . '"');
         }
     }
     if (count($strControlIdToRegister)) {
         $strEndScript .= sprintf('qc.regCA(new Array(%s)); ', implode(',', $strControlIdToRegister));
     }
     // Next, run any GetEndScrips on Controls and Groupings
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             $strEndScript .= $objControl->GetEndScript();
         }
     }
     foreach ($this->objGroupingArray as $objGrouping) {
         $strEndScript .= $objGrouping->Render();
     }
     // Run End Script Compressor
     $strEndScriptArray = explode('; ', $strEndScript);
     $strEndScriptCommands = array();
     foreach ($strEndScriptArray as $strEndScript) {
         $strEndScriptCommands[trim($strEndScript)] = true;
     }
     $strEndScript = implode('; ', array_keys($strEndScriptCommands));
     // Finally, add any application level js commands
     $strEndScript .= QApplication::RenderJavaScript(false);
     // Next, go through all controls and gather up any JS or CSS to run or Form Attributes to modify
     // due to dynamically created controls
     $strJavaScriptToAddArray = array();
     $strStyleSheetToAddArray = array();
     $strFormAttributeToModifyArray = array();
     foreach ($this->GetAllControls() as $objControl) {
         // Include any JavaScripts?  The control would have a
         // comma-delimited list of javascript files to include (if applicable)
         if ($strScriptArray = $this->ProcessJavaScriptList($objControl->JavaScripts)) {
             $strJavaScriptToAddArray = array_merge($strJavaScriptToAddArray, $strScriptArray);
         }
         // Include any StyleSheets?  The control would have a
         // comma-delimited list of stylesheet files to include (if applicable)
         if ($strScriptArray = $this->ProcessStyleSheetList($objControl->StyleSheets)) {
             $strStyleSheetToAddArray = array_merge($strStyleSheetArray, $strScriptArray);
         }
         // Form Attributes?
         if ($objControl->FormAttributes) {
             foreach ($objControl->FormAttributes as $strKey => $strValue) {
                 if (!array_key_exists($strKey, $this->strFormAttributeArray)) {
                     $this->strFormAttributeArray[$strKey] = $strValue;
                     $strFormAttributeToModifyArray[$strKey] = $strValue;
                 } else {
                     if ($this->strFormAttributeArray[$strKey] != $strValue) {
                         $this->strFormAttributeArray[$strKey] = $strValue;
                         $strFormAttributeToModifyArray[$strKey] = $strValue;
                     }
                 }
             }
         }
     }
     // Finally, render the JS Commands to Execute
     // First, alter any <Form> settings that need to be altered
     foreach ($strFormAttributeToModifyArray as $strKey => $strValue) {
         $strEndScript .= sprintf('document.getElementById("%s").%s = "%s"; ', $this->strFormId, $strKey, $strValue);
     }
     // Next, add any new CSS files that haven't yet been included to the end of the High Priority commands string
     foreach ($strStyleSheetToAddArray as $strScript) {
         $strEndScript .= 'qc.loadStyleSheetFile("' . $strScript . '", "all"); ';
     }
     // Next, add any new JS files that haven't yet been included to the BEGINNING of the High Priority commands string
     // (already rendered HP commands up to this point will be placed into the callback)
     foreach ($strJavaScriptToAddArray as $strScript) {
         if ($strEndScript) {
             $strEndScript = 'qc.loadJavaScriptFile("' . $strScript . '", function() {' . $strEndScript . '}); ';
         } else {
             $strEndScript = 'qc.loadJavaScriptFile("' . $strScript . '", null); ';
         }
     }
     // Finally, add qcodo includes path
     $strEndScript = sprintf('qc.jsAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __JS_ASSETS__) . $strEndScript;
     $strEndScript = sprintf('qc.phpAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __PHP_ASSETS__) . $strEndScript;
     $strEndScript = sprintf('qc.cssAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __CSS_ASSETS__) . $strEndScript;
     $strEndScript = sprintf('qc.imageAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __IMAGE_ASSETS__) . $strEndScript;
     // Create Final EndScript Script
     $strEndScript = sprintf('<script type="text/javascript">qc.registerForm(); %s</script>', $strEndScript);
     // Persist Controls (if applicable)
     foreach ($this->objPersistentControlArray as $objControl) {
         $objControl->Persist();
     }
     // Clone Myself
     $objForm = clone $this;
     // Render HTML
     $strToReturn = "\r\n<div style=\"display: none;\">\r\n\t";
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormState" id="Qform__FormState" value="%s" />', QForm::Serialize($objForm));
     $strToReturn .= "\r\n\t";
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormId" id="Qform__FormId" value="%s" />', $this->strFormId);
     $strToReturn .= "\r\n</div>\r\n";
     // The Following "Hidden Form Variables" are no longer explicitly rendered in HTML, but are now
     // added to the DOM by the Qcodo JavaScript Library method qc.initialize():
     // * Qform__FormControl
     // * Qform__FormEvent
     // * Qform__FormParameter
     // * Qform__FormCallType
     // * Qform__FormUpdates
     // * Qform__FormCheckableControls
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             $strToReturn .= $objControl->GetEndHtml();
         }
     }
     $strToReturn .= "\n</form>";
     $strToReturn .= $strEndScript;
     if ($this->blnRenderedBodyTag) {
         $strToReturn .= '</body>';
     }
     // Update Form Status
     $this->intFormStatus = QFormBase::FormStatusRenderEnded;
     // Display or Return
     if ($blnDisplayOutput) {
         print $strToReturn;
         return null;
     } else {
         return $strToReturn;
     }
 }
Example #30
0
 protected function RenderEnd($blnDisplayOutput = true)
 {
     // Ensure that RenderEnd() has not yet been called
     switch ($this->intFormStatus) {
         case QFormBase::FormStatusUnrendered:
             throw new QCallerException('$this->RenderBegin() was never called');
         case QFormBase::FormStatusRenderBegun:
             break;
         case QFormBase::FormStatusRenderEnded:
             throw new QCallerException('$this->RenderEnd() has already been called');
             break;
         default:
             throw new QCallerException('FormStatus is in an unknown status');
     }
     // Get End Script
     $strEndScript = '';
     // First, regC on all Controls
     $strControlIdToRegister = array();
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             array_push($strControlIdToRegister, '"' . $objControl->ControlId . '"');
         }
     }
     if (count($strControlIdToRegister)) {
         $strEndScript = sprintf('qc.regCA(new Array(%s)); ', implode(',', $strControlIdToRegister));
     }
     // Next, run any GetEndScrips on Controls and Groupings
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             $strEndScript .= $objControl->GetEndScript();
         }
     }
     foreach ($this->objGroupingArray as $objGrouping) {
         $strEndScript .= $objGrouping->Render();
     }
     // Run End Script Compressor
     $strEndScriptArray = explode('; ', $strEndScript);
     $strEndScriptCommands = array();
     foreach ($strEndScriptArray as $strEndScript) {
         $strEndScriptCommands[trim($strEndScript)] = true;
     }
     $strEndScript = implode('; ', array_keys($strEndScriptCommands));
     // Next, add qcodo includes path
     $strEndScript .= sprintf('qc.jsAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __JS_ASSETS__);
     $strEndScript .= sprintf('qc.phpAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __PHP_ASSETS__);
     $strEndScript .= sprintf('qc.cssAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __CSS_ASSETS__);
     $strEndScript .= sprintf('qc.imageAssets = "%s"; ', __VIRTUAL_DIRECTORY__ . __IMAGE_ASSETS__);
     // Finally, add any application level js commands
     $strEndScript .= QApplication::RenderJavaScript(false);
     // Create Final EndScript Script
     $strEndScript = sprintf('<script type="text/javascript">qc.registerForm(); %s</script>', $strEndScript);
     // Clone Myself
     $objForm = clone $this;
     // Render HTML
     $strToReturn = "\r\n<div>\r\n\t";
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormState" id="Qform__FormState" value="%s" />', QForm::Serialize($objForm));
     $strToReturn .= "\r\n\t";
     $strToReturn .= sprintf('<input type="hidden" name="Qform__FormId" id="Qform__FormId" value="%s" />', $this->strFormId);
     $strToReturn .= "\r\n</div>\r\n";
     //			$strToReturn .= "\n\t";
     //			$strToReturn .= '<input type="hidden" name="Qform__FormControl" id="Qform__FormControl" value="" />';
     //			$strToReturn .= '<input type="hidden" name="Qform__FormEvent" id="Qform__FormEvent" value="" />';
     //			$strToReturn .= '<input type="hidden" name="Qform__FormParameter" id="Qform__FormParameter" value="" />';
     //			$strToReturn .= '<input type="hidden" name="Qform__FormCallType" id="Qform__FormCallType" value="" />';
     //			$strToReturn .= '<input type="hidden" name="Qform__FormUpdates" id="Qform__FormUpdates" value="" />';
     //			$strToReturn .= '<input type="hidden" name="Qform__FormCheckableControls" id="Qform__FormCheckableControls" value="" />';
     /*			$strToReturn .= '<div id="Qform_Logger" style="display:none;width:400px;background-color:#dddddd;font-size:10px;font-family:lucida console, courier, monospaced;padding:6px;';
     			if (QApplication::IsBrowser(QBrowserType::InternetExplorer))
     				$strToReturn .= 'filter:alpha(opacity=50);';
     			else
     				$strToReturn .= 'opacity:0.5;';
     			$strToReturn .= 'overflow:auto;"></div>';*/
     foreach ($this->GetAllControls() as $objControl) {
         if ($objControl->Rendered) {
             $strToReturn .= $objControl->GetEndHtml();
         }
     }
     $strToReturn .= "\n</form>";
     $strToReturn .= $strEndScript;
     if ($this->blnRenderedBodyTag) {
         $strToReturn .= '</body>';
     }
     // Update Form Status
     $this->intFormStatus = QFormBase::FormStatusRenderEnded;
     // Display or Return
     if ($blnDisplayOutput) {
         print $strToReturn;
         return null;
     } else {
         return $strToReturn;
     }
 }