public function getContents()
 {
     $this->label = 'Change Your Password';
     $this->description = 'Please use this form to change your current password';
     $form = Element::create('Form')->add(Element::create('PasswordField', 'Current Password', 'current_password')->setRequired(true)->setEncrypted(false), Element::create('PasswordField', 'New Password', 'new_password')->setRequired(true)->setEncrypted(false), Element::create('PasswordField', 'Retype New Password', 'repeat_new_password')->setRequired(true)->setEncrypted(false));
     $form->addAttribute('style', 'width:500px');
     $form->setCallback($this->getClassName() . '::callback', $this);
     return $form->render();
 }
Example #2
0
 /**
  * Element constructor.
  *
  * @param array $variables
  *   A theme hook variables array.
  */
 public function __construct(array &$variables)
 {
     $this->array =& $variables;
     if (isset($variables['element'])) {
         $this->element = Element::create($variables['element']);
     } elseif (isset($variables['elements'])) {
         $this->element = Element::create($variables['elements']);
     }
 }
 /**
  * Creates and returns a category object
  * 
  * @param string $name
  * @param int $parent_id
  * 
  * @return Element | boolean
  */
 private function create_category($name, $parent_id = 0)
 {
     $category = Element::get($this->modx, 'modCategory', $name);
     if (!$category) {
         $category = Element::create($this->modx, 'modCategory', $name);
     }
     $properties = array('parent' => $parent_id);
     if ($category->set_properties($properties)) {
         return $category;
     }
     return false;
 }
 protected function setupList()
 {
     parent::setupList();
     $this->selectionLists = $this->retrieveSelectionLists();
     foreach ($this->selectionLists as $list) {
         $selectionList = Element::create("SelectionListToolbarItem", "{$list['filter_label']}");
         $this->addListItems($selectionList, $list);
         $this->filterFieldModel = $this->model;
         $selectionList->onchange = "wyf.updateFilter('{$this->table->name}', '{$this->filterFieldModel->database}.{$list['filter_field']}', this.value)";
         $this->toolbar->add($selectionList);
     }
 }
Example #5
0
 public function getImporterForm()
 {
     $key = $this->parentController->model->getKeyField();
     $form = parent::getForm();
     $list = Element::create('SelectionList', Utils::singular($this->parentController->model->getEntity()), $key);
     $items = $this->parentController->model->get();
     foreach ($items as $item) {
         $this->parentController->model->setData($item);
         $list->addOption((string) $this->parentController->model, $item[$key]);
     }
     $form->add($list);
     return $form;
 }
Example #6
0
 public function roles($params)
 {
     //Load necessary models
     $usersModel = Model::load("auth.users");
     $usersRolesModel = Model::load("auth.users_roles");
     $rolesModel = Model::load("auth.roles");
     //required queries
     $user = $usersModel->getWithField("user_id", $params[0]);
     $usersRoles = $usersRolesModel->getWithField("user_id", $params[0]);
     $loggedInUsersRoles = $usersRolesModel->getWithField("user_id", $_SESSION['user_id']);
     $roles = $rolesModel->get();
     $this->label = "Select Role(s) for " . $user[0]['first_name'] . " " . $user[0]['last_name'];
     //create a new form
     $form = new Form();
     $form->setRenderer("table");
     $fieldset = Element::create('ColumnContainer', 3);
     $form->add($fieldset);
     foreach ($roles as $role) {
         if ($role['role_id'] == 1) {
             //Boolean to determine if the outer foreach loop should "continue" particular loop or not
             $continueBool = false;
             //Loop through all the current user's
             foreach ($loggedInUsersRoles as $userRole) {
                 if ($userRole['role_id'] == 1) {
                     $continueBool = false;
                     break;
                 } else {
                     $continueBool = true;
                 }
             }
             if ($continueBool) {
                 continue;
             }
         }
         $checkbox = Element::create("Checkbox", $role['role_name'], self::underscore($role['role_name']), "", $role['role_id']);
         foreach ($usersRoles as $userRole) {
             if ($userRole['role_id'] == $role['role_id']) {
                 $checkbox->setValue($role['role_id']);
             }
         }
         $fieldset->add($checkbox);
     }
     $userIdHiddenField = Element::create("HiddenField", "user_id", $params[0]);
     $form->add($userIdHiddenField);
     $form->setValidatorCallback("{$this->getClassName()}::roles_callback");
     $form->setShowClear(false);
     //render the form
     return $form->render();
 }
Example #7
0
 public function manage()
 {
     if (isset($_POST['is_form_sent'])) {
         $this->postNewNote();
         return;
     }
     $notes = SQLDBDataStore::getMulti(array('fields' => array('system.notes.note_id', 'system.notes.note', 'system.notes.note_time', 'system.users.first_name', 'system.users.last_name'), 'filter' => 'item_type = ? and item_id = ?', 'bind' => [$this->model->package, $params[0]]));
     foreach ($notes as $i => $note) {
         $attachments = $noteAttachments->getWithField2('note_id', $note['note_id']);
         foreach ($attachments as $j => $attachment) {
             $attachments[$j]['path'] = PgFileStore::getFilePath($attachment['object_id'], $attachment['description']);
         }
         $notes[$i]['attachments'] = $attachments;
     }
     $form = Element::create('Form')->add(Element::create('TextArea', 'Note', 'note'), Element::create('FieldSet', 'Add Attachments')->add(Element::create('UploadField', 'Attachment', 'attachment_1'), Element::create('UploadField', 'Attachment', 'attachment_2'), Element::create('UploadField', 'Attachment', 'attachment_3'), Element::create('UploadField', 'Attachment', 'attachment_4'))->setId('attachments')->setCollapsible(true))->setRenderer('default');
     return $this->arbitraryTemplate('lib/controllers/notes.tpl', array('form' => $form->render(), 'notes' => $notes, 'route' => $this->path, 'id' => $params[0]));
 }
Example #8
0
 private function getElement($element, $field)
 {
     return Element::create($element, $field['label'], $field['name'], $field['description']);
 }
 /**
  * Returns a form to be used to filter the report. This method analyses the
  * XML file and uses the fields specified in there to generate a very form
  * which allows you to define filter for the form. The form generated also
  * gives you options to sort and group the reports.
  * @return Form
  */
 public function getForm()
 {
     $this->initializeForm();
     $filters = array();
     $fieldInfos = array();
     $queries = $this->xml->xpath("/rapi:report/rapi:query");
     $tables = $this->xml->xpath("/rapi:report/rapi:table");
     /// Filters and sorting.
     foreach ($tables as $table) {
         $numConcatFields = 0;
         $fields = $table->xpath("/rapi:report/rapi:table[@name='{$table["name"]}']/rapi:fields/rapi:field");
         $labels = $table->xpath("/rapi:report/rapi:table[@name='{$table["name"]}']/rapi:fields/rapi:field/@label");
         $filters = new TableLayout(count($fields) + 1, 5);
         $filters->add(Element::create("Label", "Field")->addCssClass("header-label"), 0, 0)->add(Element::create("Label", "Options")->addCssClass("header-label"), 0, 1)->add(Element::create("Label", "Exclude")->addCssClass("header-label"), 0, 4)->resetCssClasses()->addCssClass("filter-table")->setRenderer("default");
         $sortingField = new SelectionList("Sorting Field", "{$table["name"]}_sorting_field");
         $grouping1 = new SelectionList();
         $i = 1;
         foreach ($fields as $key => $field) {
             if (isset($field["labelsField"])) {
                 continue;
             }
             if (count(explode(",", (string) $field)) == 1) {
                 $fieldInfo = Model::resolvePath((string) $field);
                 $model = Model::load($fieldInfo["model"]);
                 $fieldName = $fieldInfo["field"];
                 $fieldInfo = $model->getFields(array($fieldName));
                 $fieldInfo = $fieldInfo[0];
                 $fields[$key] = (string) $field;
                 $sortingField->addOption(str_replace("\\n", " ", $fieldInfo["label"]), $model->getDatabase() . "." . $fieldInfo["name"]);
                 $grouping1->addOption(str_replace("\\n", " ", $field["label"]), (string) $field);
                 if (array_search($model->getKeyField(), $this->referencedFields) === false || $fieldInfo["type"] == "double" || $fieldInfo["type"] == "date") {
                     switch ($fieldInfo["type"]) {
                         case "integer":
                         case "double":
                             $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Equals", "EQUALS")->addOption("Greater Than", "GREATER")->addOption("Less Than", "LESS")->addOption("Between", "BETWEEN")->setValue("BETWEEN"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_start_value")->setAsNumeric(), $i, 2)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_end_value")->setAsNumeric(), $i, 3);
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                         case "date":
                         case "datetime":
                             $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Before", "LESS")->addOption("After", "GREATER")->addOption("On", "EQUALS")->addOption("Between", "BETWEEN")->setValue("BETWEEN"), $i, 1)->add(Element::create("DateField", "", "{$table["name"]}.{$fieldInfo["name"]}_start_date")->setId("{$table["name"]}_{$fieldInfo["name"]}_start_date"), $i, 2)->add(Element::create("DateField", "", "{$table["name"]}.{$fieldInfo["name"]}_end_date")->setId("{$table["name"]}_{$fieldInfo["name"]}_end_date"), $i, 3);
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                         case "enum":
                             $enum_list = new SelectionList("", "{$table["name"]}.{$fieldInfo["name"]}_value");
                             $enum_list->setMultiple(true);
                             foreach ($fieldInfo["options"] as $value => $label) {
                                 $enum_list->addOption($label, $value);
                             }
                             if (!isset($field["value"])) {
                                 $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is any of", "INCLUDE")->addOption("Is none of", "EXCLUDE")->setValue("INCLUDE"), $i, 1)->add($enum_list, $i, 2);
                             }
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                         case "string":
                         case "text":
                             $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is exactly", "EXACTLY")->addOption("Contains", "CONTAINS")->setValue("CONTAINS"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}.{$fieldInfo["name"]}_value"), $i, 2);
                             //->add(Element::create("Checkbox","","{$table["name"]}.{$fieldInfo["name"]}_ignore","","1"),$i,4);
                             break;
                     }
                     if (isset($field["hide"])) {
                         $filters->add(Element::create("HiddenField", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "1"), $i, 4);
                     } else {
                         $filters->add(Element::create("Checkbox", "", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "", "1"), $i, 4);
                     }
                 } else {
                     $enum_list = new ModelSearchField();
                     $enum_list->setName("{$table["name"]}.{$fieldInfo["name"]}_value");
                     $enum_list->setModel($model, $fieldInfo["name"]);
                     $enum_list->addSearchField($fieldInfo["name"]);
                     $enum_list->boldFirst = false;
                     $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}.{$fieldInfo["name"]}_option")->addOption("Is any of", "IS_ANY_OF")->addOption("Is none of", "IS_NONE_OF")->setValue("IS_ANY_OF"), $i, 1)->add(Element::create("MultiFields")->setTemplate($enum_list), $i, 2)->add(Element::create("Checkbox", "", "{$table["name"]}.{$fieldInfo["name"]}_ignore", "", "1"), $i, 4);
                 }
             } else {
                 $grouping1->addOption(str_replace("\\n", " ", $field["label"]), $field);
                 $filters->add(Element::create("Label", str_replace("\\n", " ", (string) $field["label"])), $i, 0)->add(Element::create("SelectionList", "", "{$table["name"]}_concat_{$numConcatFields}_option")->addOption("Is exactly", "EXACTLY")->addOption("Contains", "CONTAINS")->setValue("CONTAINS"), $i, 1)->add(Element::create("TextField", "", "{$table["name"]}_concat_{$numConcatFields}_value"), $i, 2)->add(Element::create("Checkbox", "", "{$table["name"]}_concat_{$numConcatFields}_ignore", "", "1"), $i, 4);
                 $numConcatFields++;
             }
             $i++;
         }
         $grouping1->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 1");
         $g1Paging = new Checkbox("Start on a new page", "grouping_1_newpage", "", "1");
         $g1Logo = new Checkbox("Repeat Logos", "grouping_1_logo", "", "1");
         $g1Summarize = new Checkbox("Summarize", "grouping_1_summary", "", "1");
         $grouping2 = clone $grouping1;
         $grouping2->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 2");
         $g2Paging = new Checkbox("Start on a new page", "grouping_2_newpage", "", "1");
         $g2Logo = new Checkbox("Repeat Logos", "grouping_2_logo", "", "1");
         $grouping3 = clone $grouping1;
         $grouping3->setName("{$table["name"]}_grouping[]")->setLabel("Grouping Field 3");
         $g3Paging = new Checkbox("Start on a new page", "grouping_3_newpage", "", "1");
         $g3Logo = new Checkbox("Repeat Logos", "grouping_3_logo", "", "1");
         $sortingField->setLabel("Sorting Field");
         $sortingField->setName($table["name"] . "_sorting");
         $groupingTable = new TableLayout(3, 4);
         $groupingTable->add($grouping1, 0, 0);
         $groupingTable->add($g1Paging, 0, 1);
         $groupingTable->add($g1Logo, 0, 2);
         $groupingTable->add($g1Summarize, 0, 3);
         $groupingTable->add($grouping2, 1, 0);
         /* $groupingTable->add($g2Paging, 1, 1);
            $groupingTable->add($g2Logo, 1, 2); */
         $groupingTable->add($grouping3, 2, 0);
         $container = new FieldSet($table["name"]);
         $container->setId("{$table["name"]}_options");
         $container->add(Element::create("FieldSet", "Filters")->add($filters)->setId("table_{$table['name']}"), Element::create("FieldSet", "Sorting & Limiting")->add($sortingField, Element::create("SelectionList", "Direction", "{$table["name"]}.sorting_direction")->addOption("Ascending", "ASC")->addOption("Descending", "DESC"), Element::create('TextField', 'Limit', "{$table['name']}.limit")->setAsNumeric())->setId("{$table['name']}_sorting_fs"), Element::create("FieldSet", "Grouping")->setId("{$table['name']}_grouping_fs")->add($groupingTable));
         $sortingField->setName($table["name"] . "_sorting");
         $this->form->add($container);
     }
     $this->form->setSubmitValue("Generate");
     $this->form->addAttribute("action", $this->path . "/generate");
     $this->form->addAttribute("target", "blank");
     return $this->form;
 }
Example #10
0
 public function __construct()
 {
     parent::__construct();
     $this->add(Element::create("TextField", "Username", "user_name"), Element::create("TextField", "Firstname", "first_name"), Element::create("TextField", "Lastname", "last_name"), Element::create("TextField", "Othernames", "other_names"), Element::create("ModelField", ".roles.role_id", "role_name"), Element::create("TextField", "Email", "email"), Element::create("HiddenField", "password"));
     $this->addAttribute("style", "width:450px");
 }
Example #11
0
 public function constraints($params)
 {
     //Load necessary Models
     $roleModel = Model::load('auth.roles');
     $constraintModel = Model::load('auth.constraints');
     $role = $roleModel->getWithField('role_id', $params[0]);
     $constraints = $constraintModel->getWithField("role_id", "{$params['0']}");
     //Label at the top of the inner template
     $this->label = "Login Constraints for the '" . $role[0]['role_name'] . "' role";
     //create a new form
     $form = new Form();
     $form->setRenderer("default");
     //Fieldset to group days of week checkboxes
     $daysFieldset = Element::create('ColumnContainer', 7);
     //create checkbox fields and set their respective values
     $mon = Element::create("Checkbox", "Monday", "mon", "", "1");
     $mon->setValue(($constraints[0]['days_of_week_value'] & 1) == 1 ? "1" : "0");
     $daysFieldset->add($mon);
     $tue = Element::create("Checkbox", "Tuesday", "tue", "", "2");
     $tue->setValue(($constraints[0]['days_of_week_value'] & 2) == 2 ? "2" : "0");
     $daysFieldset->add($tue);
     $wed = Element::create("Checkbox", "Wednesday", "wed", "", "4");
     $wed->setValue(($constraints[0]['days_of_week_value'] & 4) == 4 ? "4" : "0");
     $daysFieldset->add($wed);
     $thu = Element::create("Checkbox", "Thursday", "thu", "", "8");
     $thu->setValue(($constraints[0]['days_of_week_value'] & 8) == 8 ? "8" : "0");
     $daysFieldset->add($thu);
     $fri = Element::create("Checkbox", "Friday", "fri", "", "16");
     $fri->setValue(($constraints[0]['days_of_week_value'] & 16) == 16 ? "16" : "0");
     $daysFieldset->add($fri);
     $sat = Element::create("Checkbox", "Saturday", "sat", "", "32");
     $sat->setValue(($constraints[0]['days_of_week_value'] & 32) == 32 ? "32" : "0");
     $daysFieldset->add($sat);
     $sun = Element::create("Checkbox", "Sunday", "sun", "", "64");
     $sun->setValue(($constraints[0]['days_of_week_value'] & 64) == 64 ? "64" : "0");
     $daysFieldset->add($sun);
     $form->add($daysFieldset);
     //FieldSet to group beginning time section
     $beginningTimeFieldset = Element::create('ColumnContainer', 2);
     //Starting times
     $timeRangeStartFieldSet = Element::create("FieldSet", "Beginning Time");
     $hourStartSelection = Element::create("SelectionList", "Hour", "hour_start");
     //add all options to the hour start selection field
     for ($i = 0; $i <= 23; $i++) {
         $hourStartSelection->addOption(sprintf("%02d", $i));
     }
     //add hour start to begin time range field set
     $beginningTimeFieldset->add($hourStartSelection);
     $minuteStartSelection = Element::create("SelectionList", "Minutes", "minutes_start");
     //add all options to the minute start selection field
     for ($i = 0; $i <= 59; $i++) {
         $minuteStartSelection->addOption(sprintf("%02d", $i));
     }
     //add minute start to begin time range field set
     $beginningTimeFieldset->add($minuteStartSelection)->addAttribute('style', 'width:30%');
     //Add the column container fieldset to the main fieldset
     $timeRangeStartFieldSet->add($beginningTimeFieldset);
     $endingTimeFieldset = Element::create('ColumnContainer', 2);
     //Ending times
     $timeRangeEndFieldSet = Element::create("FieldSet", "Ending Time");
     $hourEndSelection = Element::create("SelectionList", "Hour", "hour_end");
     //add all options to the hour end selection field
     for ($i = 0; $i <= 23; $i++) {
         $hourEndSelection->addOption(sprintf("%02d", $i));
     }
     $endingTimeFieldset->add($hourEndSelection);
     $minuteEndSelection = Element::create("SelectionList", "Minutes", "minutes_end");
     //add all options to the minute end selection field
     for ($i = 0; $i <= 59; $i++) {
         $minuteEndSelection->addOption(sprintf("%02d", $i));
     }
     $endingTimeFieldset->add($minuteEndSelection)->addAttribute('style', 'width:30%');
     //Add the column container fieldset to the main fieldset
     $timeRangeEndFieldSet->add($endingTimeFieldset);
     $modeSelection = new SelectionList("Mode", "mode");
     $modeSelection->addOption("Allow", "allow");
     $modeSelection->addOption("Deny", "deny");
     $roleIdHiddenField = Element::create("HiddenField", "role_id", $params[0]);
     //populate fields with values from database if the data for that partular role already exists
     if ($constraints[0] != null) {
         $hourStartSelection->setValue(substr($constraints[0]['time_range_start'], 0, 2));
         $hourEndSelection->setValue(substr($constraints[0]['time_range_end'], 0, 2));
         $minuteStartSelection->setValue(substr($constraints[0]['time_range_start'], 3));
         $minuteEndSelection->setValue(substr($constraints[0]['time_range_end'], 3));
         $modeSelection->setValue($constraints[0]['mode']);
     }
     //Add components to the form
     $form->add($timeRangeStartFieldSet);
     $form->add($timeRangeEndFieldSet);
     $form->add($modeSelection);
     $form->add($roleIdHiddenField);
     $form->setValidatorCallback("{$this->getClassName()}::constraint_callback");
     $form->setShowClear(false);
     //render the form
     return $form->render();
 }
Example #12
0
 protected function addEnumerationFilter($label, $name, $options)
 {
     $enum_list = new SelectionList("", "{$name}_value");
     $enum_list->setMultiple(true);
     foreach ($options as $value => $label) {
         $enum_list->addOption($label, $value);
     }
     $this->filters->add(Element::create("Label", str_replace("\\n", " ", $label)), $this->numFilters, 0)->add(Element::create("SelectionList", "", "{$name}_option")->addOption("Is any of", "INCLUDE")->addOption("Is none of", "EXCLUDE")->setValue("INCLUDE"), $this->numFilters, 1)->add($enum_list, $this->numFilters, 2);
     $this->numFilters++;
 }
Example #13
0
 /**
  * Provides all the necessary forms needed to start an update.
  * @param $params
  * @return string
  */
 public function import()
 {
     $this->label = "Import " . $this->label;
     $form = new Form();
     $form->add(Element::create("UploadField", "File", "file", "Select the file you want to upload."), Element::create("Checkbox", "Break on errors", "break_on_errors", "", "1")->setValue("1"));
     $form->addAttribute("style", "width:50%");
     $form->setCallback($this->getClassName() . '::importCallback', $this);
     $form->setSubmitValue('Import Data');
     return $this->arbitraryTemplate(Application::getWyfHome('model_controller/import.tpl'), array('form' => $form->render(), 'template' => "{$this->path}/export/csv?template=yes"));
 }
Example #14
0
 public function __construct()
 {
     parent::__construct();
     $this->add(Element::create('ModelField', '.users.user_id', 'user_name'), Element::create('TextField', 'API Key', 'key')->addAttribute('disabled', 'disabled'), Element::create('TextField', 'Secret', 'secret')->addAttribute('disabled', 'disabled'));
 }
Example #15
0
 /**
  * Set the table's rows
  *
  * @param array $rows
  *
  * @return self
  */
 public function rows(array $rows = array())
 {
     // Cancel if no rows
     if (!$rows) {
         return $this;
     }
     // Create tbody
     $tbody = Element::create('tbody');
     foreach ($rows as $row) {
         $tr = Element::create('tr');
         foreach ($row as $column => $value) {
             $td = Element::create('td', $value);
             $tr->setChild($td);
         }
         $tbody->setChild($tr);
     }
     // Nest into table
     $this->nest(array('tbody' => $tbody));
     return $this;
 }
Example #16
0
 public function notes($params)
 {
     $noteAttachments = Model::load('system.note_attachments');
     if ($params[1] == 'delete') {
         $model = Model::load('system.notes');
         $model->delete('note_id', $params[2]);
         Application::redirect("{$this->path}/notes/{$params[0]}");
     }
     if (isset($_POST['is_form_sent'])) {
         $model = Model::load('system.notes');
         $model->datastore->beginTransaction();
         $data = array('note' => $_POST['note'], 'note_time' => time(), 'item_id' => $params[0], 'user_id' => $_SESSION['user_id'], 'item_type' => $this->model->package);
         $model->setData($data);
         $id = $model->save();
         for ($i = 1; $i < 5; $i++) {
             $file = $_FILES["attachment_{$i}"];
             if ($file['error'] == 0) {
                 $noteAttachments->setData(array('note_id' => $id, 'description' => $file['name'], 'object_id' => PgFileStore::addFile($file['tmp_name'])));
                 $noteAttachments->save();
             }
         }
         $model->datastore->endTransaction();
         Application::redirect("{$this->urlPath}/notes/{$params[0]}");
     }
     $notes = SQLDBDataStore::getMulti(array('fields' => array('system.notes.note_id', 'system.notes.note', 'system.notes.note_time', 'system.users.first_name', 'system.users.last_name'), 'conditions' => Model::condition(array('item_type' => $this->model->package, 'item_id' => $params[0]))));
     foreach ($notes as $i => $note) {
         $attachments = $noteAttachments->getWithField2('note_id', $note['note_id']);
         foreach ($attachments as $j => $attachment) {
             $attachments[$j]['path'] = PgFileStore::getFilePath($attachment['object_id'], $attachment['description']);
         }
         $notes[$i]['attachments'] = $attachments;
     }
     $this->label = "Notes on item";
     $form = Element::create('Form')->add(Element::create('TextArea', 'Note', 'note'), Element::create('FieldSet', 'Add Attachments')->add(Element::create('UploadField', 'Attachment', 'attachment_1'), Element::create('UploadField', 'Attachment', 'attachment_2'), Element::create('UploadField', 'Attachment', 'attachment_3'), Element::create('UploadField', 'Attachment', 'attachment_4'))->setId('attachments')->setCollapsible(true))->setRenderer('default');
     return $this->arbitraryTemplate(Application::getWyfHome('controllers/notes.tpl'), array('form' => $form->render(), 'notes' => $notes, 'route' => $this->path, 'id' => $params[0]));
 }
Example #17
0
 public static function create($name, $data)
 {
     return parent::create($name, $data);
 }
Example #18
0
 /**
  * Element constructor.
  *
  * @param array $variables
  *   A theme hook variables array.
  */
 public function __construct(array &$variables)
 {
     $this->array =& $variables;
     $this->element = isset($variables['element']) ? Element::create($variables['element']) : FALSE;
 }
Example #19
0
 public function getForm()
 {
     $form = parent::getForm();
     $form->add(Element::create('HiddenField', $this->parentController->model->getKeyField(), $this->parentItemId));
     return $form;
 }
$log_prefix = '[ElementHelper] modTemplateVar: ';
$tv_file_path = MODX_BASE_PATH . $modx->getOption('elementhelper.tv_file_path', null, 'site/elements/template_variables.json');
if (file_exists($tv_file_path)) {
    $tv_file_contents = file_get_contents($tv_file_path);
    $tv_file_mod_time = filemtime($tv_file_path);
    $tvs = $tv_file_contents !== '' ? json_decode($tv_file_contents) : array();
    $flagged_tvs = array();
    // Loop through the template variables in the file
    foreach ($tvs as $i => $tv) {
        $element = Element::get($modx, 'modTemplateVar', $tv->name);
        // If the element is not in the sync
        if (!$element_sync->has_element('modTemplateVar', $tv->name)) {
            // If the tv doesn't exist
            if (!$element) {
                // Create the element
                $element = Element::create($modx, 'modTemplateVar', $tv->name);
                // If the element is created successfully
                if ($element) {
                    $properties = $element_helper->get_tv_element_properties($tv);
                    // If templates have been specified and permission to pair tvs with templates has been given
                    if (isset($tv->template_access) && $modx->getOption('elementhelper.tv_access_control', null, false) == true) {
                        $element_helper->setup_tv_template_access($element->get_property('id'), $tv->template_access);
                    }
                    // If a media source has been specified assign it to the TV
                    if (isset($tv->media_source)) {
                        $element_helper->setup_tv_media_source($element->get_property('id'), $tv->media_source);
                    }
                    // Set the tv properties and then add it to the sync
                    if ($element->set_properties($properties)) {
                        $element_sync->add_element('modTemplateVar', $tv->name, $tv_file_mod_time);
                    }
Example #21
0
 /**
  * Provides all the necessary forms needed to start an update.
  * @param $params
  * @return unknown_type
  */
 public function import($params)
 {
     if ($params[0] == 'execute') {
         $this->doImport();
         die;
     }
     $data = array();
     $form = new Form();
     $form->add(Element::create("FileUploadField", "File", "file", "Select the file you want to upload.")->setScript($this->urlPath . "/import/execute")->setJsExpression("wyf.showUploadedData(callback_data)"), Element::create("Checkbox", "Break on errors", "break_on_errors", "", "1")->setValue("1"));
     $form->setRenderer("default");
     $form->addAttribute("style", "width:400px");
     $form->setShowSubmit(false);
     $data["form"] = $form->render();
     return array("template" => "file:" . getcwd() . "/lib/controllers/import.tpl", "data" => $data);
 }
Example #22
0
 /**
  * Provides all the necessary forms needed to start an update.
  * @param $params
  * @return string
  */
 public function import()
 {
     $this->label = "Import " . $this->label;
     $entity = $this->model->getEntity();
     $path = $this->urlPath;
     $form = new Form();
     $form->setRenderer('default');
     $form->add(Element::create("HTMLBox", "This import utility would assist you to import new {$entity} into your database. You are expected to upload a CSV file which contains the data you want to import." . " <p>Please click <a href='{$path}/export/csv?template=yes'>here</a> to download a template csv file.</p>"), Element::create("UploadField", "File", "file", "Select the file you want to upload."));
     $form->addAttribute("style", "width:50%");
     $form->setCallback($this->getClassName() . '::importCallback', $this);
     $form->setSubmitValue('Import Data');
     return $this->arbitraryTemplate(Application::getWyfHome('utils/model_controller/templates/import.tpl'), array('form' => $form->render()));
 }