Ejemplo n.º 1
0
 public function testIterator()
 {
     $model = new AnyDataset();
     $model->AddField("id", 10);
     $model->AddField("name", 'Testing');
     $model->appendRow();
     $model->AddField("id", 20);
     $model->AddField("name", 'Other');
     $iterator = $model->getIterator();
     $object = new SerializerObject($iterator->toArray());
     $result = $object->build();
     $this->assertEquals([["id" => 10, "name" => "Testing"], ["id" => 20, "name" => "Other"]], $result);
 }
Ejemplo n.º 2
0
 /**
  * Add new user in database
  *
  * @param string $name
  * @param string $userName
  * @param string $email
  * @param string $password
  * @return bool
  * @throws UserExistsException
  */
 public function addUser($name, $userName, $email, $password)
 {
     if ($this->getByEmail($email) !== null) {
         throw new UserExistsException('Email already exists');
     }
     if ($this->getByUsername($userName) !== null) {
         throw new UserExistsException('Username already exists');
     }
     $userId = $this->generateUserId();
     $fixedUsername = preg_replace('/(?:([\\w])|([\\W]))/', '\\1', strtolower($userName));
     if (is_null($userId)) {
         $userId = $fixedUsername;
     }
     $this->_anyDataSet->appendRow();
     $this->_anyDataSet->addField($this->getUserTable()->id, $userId);
     $this->_anyDataSet->addField($this->getUserTable()->username, $fixedUsername);
     $this->_anyDataSet->addField($this->getUserTable()->name, $name);
     $this->_anyDataSet->addField($this->getUserTable()->email, strtolower($email));
     $this->_anyDataSet->addField($this->getUserTable()->password, $this->getPasswordHash($password));
     $this->_anyDataSet->addField($this->getUserTable()->admin, "");
     $this->_anyDataSet->addField($this->getUserTable()->created, date("Y-m-d H:i:s"));
     return true;
 }
Ejemplo n.º 3
0
 /**
  * @return SingleRow
  */
 public function moveNext()
 {
     if ($this->hasNext()) {
         $key = $this->_keys[$this->_currentRow];
         $cols = $this->_rows[$key];
         $any = new AnyDataset();
         $any->appendRow();
         $any->addField("__id", $this->_currentRow);
         $any->addField("__key", $key);
         foreach ($cols as $key => $value) {
             $any->addField(strtolower($key), $value);
         }
         $it = $any->getIterator(null);
         $sr = $it->moveNext();
         $this->_currentRow++;
         return $sr;
     } else {
         return null;
     }
 }
Ejemplo n.º 4
0
 /**
  *
  * @param string $name
  * @param ChartColumnType $type
  * @param string $data
  */
 public function addSerie($name, $type, $data)
 {
     $iter = $this->_Serie->getIterator();
     if ($iter->Count() == 0) {
         $this->_Serie->addField('data_0', "'{$name}'");
         foreach ($data as $item) {
             if ($type == ChartColumnType::String) {
                 $item = "'" . FromUTF8::removeAccent($item) . "'";
             } else {
                 if ($type == ChartColumnType::Number) {
                     $item = intval($item);
                 } else {
                     throw new UnexpectedValueException('Unexpected Chat Column Type - ' . $type);
                 }
             }
             $this->_Serie->appendRow();
             $this->_Serie->addField('data_0', $item);
         }
     } else {
         $serieCount = null;
         foreach ($iter as $row) {
             if ($serieCount == null) {
                 $serieCount = count($row->toArray());
                 $row->addField("data_{$serieCount}", "'{$name}'");
             } else {
                 if (count($data) > 0) {
                     if ($type == ChartColumnType::String) {
                         $item = "'" . array_shift($data) . "'";
                     } else {
                         if ($type == ChartColumnType::Number) {
                             $item = intval(array_shift($data));
                         } else {
                             throw new UnexpectedValueException('Unexpected Chat Column Type - ' . $type);
                         }
                     }
                     $row->addField("data_{$serieCount}", $item);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  *@desc Generate $page, processing yours childs.
  *@param DOMNode $current
  *@return void
  */
 public function generateObject($current)
 {
     $nodeWorking = XmlUtil::CreateChild($current, "editlist", "");
     XmlUtil::AddAttribute($nodeWorking, "module", $this->_module);
     XmlUtil::AddAttribute($nodeWorking, "title", $this->_title);
     XmlUtil::AddAttribute($nodeWorking, "name", $this->_name);
     if ($this->_new) {
         XmlUtil::AddAttribute($nodeWorking, "new", "true");
     }
     if ($this->_edit) {
         XmlUtil::AddAttribute($nodeWorking, "edit", "true");
     }
     if ($this->_view) {
         XmlUtil::AddAttribute($nodeWorking, "view", "true");
     }
     if ($this->_delete) {
         XmlUtil::AddAttribute($nodeWorking, "delete", "true");
     }
     if ($this->_readonly) {
         XmlUtil::AddAttribute($nodeWorking, "readonly", "true");
     }
     if ($this->_selecttype == SelectType::CHECKBOX) {
         XmlUtil::AddAttribute($nodeWorking, "selecttype", "check");
     }
     if ($this->_extraParam != null) {
         foreach ($this->_extraParam as $key => $value) {
             $param = XmlUtil::CreateChild($nodeWorking, "param", "");
             XmlUtil::AddAttribute($param, "name", $key);
             XmlUtil::AddAttribute($param, "value", $value);
         }
     }
     $processor = new ParamProcessor();
     if ($this->_customButton != null) {
         for ($i = 0, $customButtonsLength = sizeof($this->_customButton); $i < $customButtonsLength; $i++) {
             //			CustomButtons $cb
             $cb = $this->_customButton[$i];
             if ($cb->enabled) {
                 $nodeButton = XmlUtil::CreateChild($nodeWorking, "button");
                 if ($cb->url != "") {
                     $cb->url = str_replace("&", "&amp;", $processor->GetFullLink($cb->url));
                 }
                 XmlUtil::AddAttribute($nodeButton, "custom", $i + 1);
                 XmlUtil::AddAttribute($nodeButton, "acao", $cb->action);
                 XmlUtil::AddAttribute($nodeButton, "alt", $cb->alternateText);
                 XmlUtil::AddAttribute($nodeButton, "url", $cb->url);
                 XmlUtil::AddAttribute($nodeButton, "img", $cb->icon);
                 XmlUtil::AddAttribute($nodeButton, "multiple", $cb->multiple);
                 XmlUtil::AddAttribute($nodeButton, "message", $cb->message);
             }
         }
     }
     $qtd = 0;
     $qtdPagina = 0;
     $page = 0;
     $started = !$this->_enablePages;
     $first = true;
     $firstRow = true;
     $summaryFields = array();
     if (!$this->_it instanceof IteratorInterface) {
         throw new InvalidArgumentException('You have to pass an IteratorInterface object to the XmlEditList');
     }
     // Generate XML With Data
     while ($this->_it->hasNext()) {
         //com.xmlnuke.anydataset.SingleRow
         $registro = $this->_it->moveNext();
         // Insert fields if none is passed.
         if (sizeof($this->_fields) == 0) {
             foreach ($registro->getFieldNames() as $key => $fieldname) {
                 $fieldtmp = new EditListField(true);
                 $fieldtmp->editlistName = $fieldname;
                 $fieldtmp->fieldData = $fieldname;
                 $fieldtmp->fieldType = EditListFieldType::TEXT;
                 $this->addEditListField($fieldtmp);
                 if (sizeof($this->_fields) == 1) {
                     $this->addEditListField($fieldtmp);
                 }
             }
         }
         // Fill values
         if ($this->_enablePages) {
             $page = intval($qtd / $this->_qtdRows) + 1;
             $started = $page == $this->_curPage;
         }
         if ($started) {
             //\DOMNode
             $row = XmlUtil::CreateChild($nodeWorking, "row", "");
             $currentNode = null;
             if (is_null($this->_fields)) {
                 throw new InvalidArgumentException("No such EditListField Object", 850);
             }
             foreach ($this->_fields as $chave => $field) {
                 if ($field->newColumn || $currentNode == null) {
                     $currentNode = XmlUtil::CreateChild($row, "field", "");
                     if ($firstRow) {
                         if (!$first) {
                             XmlUtil::AddAttribute($currentNode, "name", $field->editlistName);
                         } else {
                             $first = false;
                         }
                         XmlUtil::AddAttribute($currentNode, "source", $field->fieldData);
                     }
                 } else {
                     XmlUtil::CreateChild($currentNode, "br", "");
                 }
                 $this->renderColumn($currentNode, $registro, $field);
                 // Check if this fields requires summary
                 if ($field->summary != EditListFieldSummary::NONE) {
                     $summaryFields[$field->fieldData] += $this->_context->Language()->getDoubleVal($registro->getField($field->fieldData));
                 }
             }
             $firstRow = false;
             $qtdPagina++;
         }
         $qtd += 1;
     }
     // Generate SUMMARY Information
     if (sizeof($summaryFields) > 0) {
         $anydata = new AnyDataset();
         $anydata->appendRow();
         foreach ($this->_fields as $chave => $field) {
             switch ($field->summary) {
                 case EditListFieldSummary::SUM:
                     $value = $summaryFields[$field->fieldData];
                     break;
                 case EditListFieldSummary::AVG:
                     $value = $summaryFields[$field->fieldData] / $qtdPagina;
                     break;
                 case EditListFieldSummary::COUNT:
                     $value = $qtdPagina;
                     break;
                 default:
                     $value = "";
                     break;
             }
             $anydata->addField($field->fieldData, $value);
         }
         $ittemp = $anydata->getIterator();
         $registro = $ittemp->moveNext();
         $row = XmlUtil::CreateChild($nodeWorking, "row", "");
         XmlUtil::AddAttribute($row, "total", "true");
         foreach ($this->_fields as $chave => $field) {
             $currentNode = null;
             if ($field->newColumn || $currentNode == null) {
                 $currentNode = XmlUtil::CreateChild($row, "field", "");
             } else {
                 XmlUtil::CreateChild($currentNode, "br", "");
             }
             $this->renderColumn($currentNode, $registro, $field);
         }
     }
     // Create other properties
     XmlUtil::AddAttribute($nodeWorking, "cols", sizeof($this->_fields));
     if ($this->_enablePages) {
         if ($this->_curPage > 1) {
             XmlUtil::AddAttribute($nodeWorking, "pageback", strval($this->_curPage - 1));
         }
         if (!$started) {
             XmlUtil::AddAttribute($nodeWorking, "pagefwd", strval($this->_curPage + 1));
         }
         XmlUtil::AddAttribute($nodeWorking, "curpage", strval($this->_curPage));
         XmlUtil::AddAttribute($nodeWorking, "offset", strval($this->_qtdRows));
         XmlUtil::AddAttribute($nodeWorking, "pages", strval($page));
     }
     if ($this->_customsubmit != "") {
         XmlUtil::AddAttribute($nodeWorking, "customsubmit", $this->_customsubmit);
     }
     if (!is_null($this->_objXmlHeader)) {
         $nodeHeader = XmlUtil::CreateChild($nodeWorking, "xmlheader", "");
         $this->_objXmlHeader->generateObject($nodeHeader);
     }
     return $nodeWorking;
 }
Ejemplo n.º 6
0
 /**
  * Get all rules from a site
  *
  * @param string $site
  * @return AnyDataset
  */
 protected function getRolesFromSite($site)
 {
     $newDataSet = new AnyDataset();
     $it = $this->user->getRolesIterator($site);
     while ($it->hasNext()) {
         $sr = $it->moveNext();
         $dataArray = $sr->getFieldArray($this->user->getRolesTable()->Role);
         if (sizeof($dataArray) > 0) {
             foreach ($dataArray as $roles) {
                 $siteName = $sr->getField($this->user->getRolesTable()->Site);
                 if ($siteName == "_all") {
                     $siteName = $this->myWords->Value("TEXT_ALLSITES");
                 }
                 $newDataSet->appendRow();
                 $newDataSet->addField($this->user->getRolesTable()->Site, $siteName);
                 $newDataSet->addField($this->user->getRolesTable()->Role, $roles);
             }
         }
     }
     return $newDataSet;
 }
Ejemplo n.º 7
0
 /**
  * Enter description here...
  *
  * @param XmlBlockCollection $block
  */
 protected function CreateSetup($block)
 {
     if ($this->_action == ModuleAction::CreateConfirm) {
         $p = new XmlParagraphCollection();
         if ($this->_context->get("type") != "-anydata-") {
             try {
                 $tblpoll = $this->_context->get("tbl_poll");
                 $tblanswer = $this->_context->get("tbl_answer");
                 $tbllastip = $this->_context->get("tbl_lastip");
                 $suffix = $this->_context->get("tablesuffix");
                 $dbdata = new DBDataset($this->_context->get("type"));
                 $results = array();
                 $results[] = $this->CreateTable($dbdata, "create table {$tblpoll}", "create table {$tblpoll} (name varchar(15), lang char(5), question varchar(150), multiple char(1), showresults char(1), active char(1)) {$suffix}");
                 $results[] = $this->CreateTable($dbdata, "create table {$tblanswer}", "create table {$tblanswer} (name varchar(15), lang char(5), code int, short varchar(10), answer varchar(50), votes int) {$suffix}");
                 //$results[] = $this->CreateTable($dbdata, "create table $tbllastip", "create table $tbllastip (name varchar(15), ip varchar(15)) $suffix");
                 $results[] = $this->CreateTable($dbdata, "add primary key poll", "alter table {$tblpoll} add constraint pk_poll primary key (name, lang);");
                 $results[] = $this->CreateTable($dbdata, "add primary key answer", "alter table {$tblanswer} add constraint pk_answer primary key (name, lang, code)");
                 //$results[] = $this->CreateTable($dbdata, "add primary key lastip", "alter table $tbllastip add constraint pk_lastip primary key (name, ip)");
                 $results[] = $this->CreateTable($dbdata, "add check poll 1", "alter table {$tblpoll} add constraint ck_poll_multiple check (multiple in ('Y', 'N'))");
                 $results[] = $this->CreateTable($dbdata, "add check poll 2", "alter table {$tblpoll} add constraint ck_poll_showresults check (showresults in ('Y', 'N'))");
                 $results[] = $this->CreateTable($dbdata, "add check poll 3", "alter table {$tblpoll} add constraint ck_poll_active check (active in ('Y', 'N'))");
                 $results[] = $this->CreateTable($dbdata, "add foreign key answer", "alter table {$tblanswer} add constraint pk_answer_poll foreign key (name) references {$tblpoll}(name)");
                 //$results[] = $this->CreateTable($dbdata, "add foreign key lastip", "alter table $tbllastip add constraint pk_lastip_poll foreign key (name) references $tblpoll(name)");
                 $block->addXmlnukeObject(new XmlEasyList(EasyListType::UNORDEREDLIST, "", $this->myWords->Value("RESULTSQL"), $results));
                 $poll = new AnydatasetFilenameProcessor("_poll");
                 $anypoll = new AnyDataset($poll);
                 $anypoll->appendRow();
                 $anypoll->addField("dbname", $this->_context->get("type"));
                 $anypoll->addField("tbl_poll", $tblpoll);
                 $anypoll->addField("tbl_answer", $tblanswer);
                 $anypoll->addField("tbl_lastip", $tbllastip);
                 $anypoll->Save();
             } catch (Exception $ex) {
                 $p->addXmlnukeObject(new XmlnukeText($this->myWords->Value("GOTERROR", $ex->getMessage())));
             }
         } else {
             $poll = new AnydatasetFilenameProcessor("_poll");
             $anypoll = new AnyDataset($poll);
             $anypoll->appendRow();
             $anypoll->addField("dbname", "-anydata-");
             $anypoll->Save();
         }
         $p->addXmlnukeObject(new XmlnukeBreakLine());
         $p->addXmlnukeObject(new XmlnukeText($this->myWords->Value("CONFIGCREATED"), true));
         $block->addXmlnukeObject($p);
     } else {
         $p = new XmlParagraphCollection();
         $p->addXmlnukeObject(new XmlnukeText($this->myWords->Value("FIRSTTIMEMESSAGE")));
         $block->addXmlnukeObject($p);
         $form = new XmlFormCollection($this->_context, $this->_moduleUrl, $this->myWords->Value("CREATESETUP"));
         $form->addXmlnukeObject(new XmlInputHidden("action", ModuleAction::CreateConfirm));
         $db = array("-anydata-" => $this->myWords->Value("NOTUSEDB"));
         $anydatafile = new AnydatasetFilenameProcessor("_db");
         $anydata = new AnyDataset($anydatafile->FullQualifiedNameAndPath());
         $it = $anydata->getIterator();
         while ($it->hasNext()) {
             $sr = $it->moveNext();
             $db[$sr->getField("dbname")] = $sr->getField("dbname");
         }
         $form->addXmlnukeObject(new XmlEasyList(EasyListType::SELECTLIST, "type", $this->myWords->Value("FORMCONN"), $db));
         $inputGroup = new XmlInputGroup($this->_context, "tabledetail", true);
         $inputGroup->setVisible(false);
         $text = new XmlInputTextBox($this->myWords->Value("TABLENAME_POLL"), "tbl_poll", "xmlnuke_poll", 20);
         $text->setRequired(true);
         $inputGroup->addXmlnukeObject($text);
         $text = new XmlInputTextBox($this->myWords->Value("TABLENAME_ANSWER"), "tbl_answer", "xmlnuke_answer", 20);
         $text->setRequired(true);
         $inputGroup->addXmlnukeObject($text);
         $text = new XmlInputTextBox($this->myWords->Value("TABLENAME_LASTIP"), "tbl_lastip", "xmlnuke_lastip", 20);
         $text->setRequired(true);
         $inputGroup->addXmlnukeObject($text);
         $text = new XmlInputTextBox($this->myWords->Value("TABLE_SUFFIX"), "tablesuffix", "TYPE INNODB", 30);
         $text->setRequired(true);
         $inputGroup->addXmlnukeObject($text);
         $form->addXmlnukeObject($inputGroup);
         $buttons = new XmlInputButtons();
         $buttons->addSubmit($this->myWords->Value("CREATESETUPBTN"));
         $form->addXmlnukeObject($buttons);
         $block->addXmlnukeObject($form);
         $javascript = "\n\t\t\t\t// ByJG \n\t\t\t\tfn_addEvent('type', 'change', enableFields);\n\t\t\t\tfunction enableFields(e) {\n\t\t    \t\tobj = document.getElementById('type');\n\t\t    \t\tshowHide_tabledetail(obj.selectedIndex != 0);\n\t\t\t\t}\n\t\t\t\t";
         $this->defaultXmlnukeDocument->addJavaScriptSource($javascript, true);
     }
 }
Ejemplo n.º 8
0
 /**
  * @param SQLType $sqlType
  */
 protected function ExecuteSQL($sqlType)
 {
     $fieldList = array();
     if ($sqlType != SQLType::SQL_DELETE) {
         // Get a SingleRow with all field values
         $anyCurInfo = new AnyDataset();
         $anyCurInfo->appendRow();
         foreach ($this->_fields as $field) {
             $anyCurInfo->addField($field->fieldName, $this->_context->get($field->fieldName));
         }
         $itCurInfo = $anyCurInfo->getIterator();
         $srCurInfo = $itCurInfo->moveNext();
         // Format and Adjust all field values
         foreach ($this->_fields as $field) {
             if ($field->editable) {
                 $value = $this->preProcessValue($field->fieldName, $field->dataType, $this->_context->get($field->fieldName));
                 if ($field->fieldXmlInput == XmlInputObjectType::FILEUPLOAD) {
                     $files = $this->_context->getUploadFileNames();
                     if ($files[$field->fieldName] == "") {
                         continue;
                     }
                     // Do nothing if none files are uploaded.
                 }
                 if ($field->beforeInsertFormatter != null) {
                     $value = $field->beforeInsertFormatter->Format($srCurInfo, $field->fieldName, $value);
                 }
                 $fieldList[$field->fieldName] = array(SQLFieldType::TEXT, $value);
             }
         }
     }
     $param = array();
     if ($sqlType != SQLType::SQL_INSERT) {
         $filter = $this->getWhereClause($param);
     } else {
         $filter = "";
     }
     $helper = new SQLHelper($this->_dbData);
     $helper->setFieldDelimeters($this->getFieldDeliLeft(), $this->getFieldDeliRight());
     $sql = $helper->generateSQL($this->_table, $fieldList, $param, $sqlType, $filter, $this->_decimalSeparator);
     $this->DebugInfo($sql, $param);
     $this->_dbData->execSQL($sql, $param);
 }
Ejemplo n.º 9
0
 /**
  * Get the user based on a filter.
  * Return SingleRow if user was found; null, otherwise
  *
  * @param IteratorFilter $filter Filter to find user
  * @return SingleRow
  * */
 public function getUser($filter)
 {
     $it = $this->getIterator($filter);
     if ($it->hasNext()) {
         // Get the Requested User
         $sr = $it->moveNext();
         $this->setCustomFieldsInUser($sr);
         // Clone the User Properties
         $anyOri = new AnyDataset();
         $anyOri->appendRow();
         foreach ($sr->getFieldNames() as $key => $fieldName) {
             $anyOri->addField($fieldName, $sr->getField($fieldName));
         }
         $itOri = $anyOri->getIterator();
         $srOri = $itOri->moveNext();
         // Store and return to the user the proper single row.
         $this->_cacheUserOriginal[$sr->getField($this->getUserTable()->id)] = $srOri;
         $this->_cacheUserWork[$sr->getField($this->getUserTable()->id)] = $sr;
         return $this->_cacheUserWork[$sr->getField($this->getUserTable()->id)];
     } else {
         return null;
     }
 }
Ejemplo n.º 10
0
 /**
  * @access public
  * @param array $options
  * @return void
  */
 public function updateCustomConfig($options)
 {
     //processor.AnydatasetFilenameProcessor
     $configFile = new AnydatasetFilenameProcessor("customconfig");
     $phyFile = $this->CurrentSitePath() . $configFile->FullQualifiedName();
     //anydataset.AnyDataset
     $config = new AnyDataset($phyFile->FullQualifiedNameAndPath());
     //anydataset.AnyIterator
     $it = $config->getIterator();
     if ($it->hasNext()) {
         $config->removeRow(0);
     }
     $config->appendRow();
     foreach (array_keys($options) as $key) {
         if (trim($options[$key]) != "") {
             $this->addPairToConfig($key, $options[$key]);
             $config->addField($key, $options[$key]);
         }
     }
     $config->Save($phyFile);
 }
Ejemplo n.º 11
0
 public function CreatePage()
 {
     parent::CreatePage();
     // Doesnt necessary get PX, because PX is protected!
     $this->myWords = $this->WordCollection();
     $this->setTitlePage($this->myWords->Value("TITLE"));
     $this->setHelp($this->myWords->Value("DESCRIPTION"));
     $this->addMenuOption($this->myWords->Value("NEWLANGUAGEFILE"), "module:Xmlnuke.Admin.EditLanguage?action=new");
     $this->addMenuOption($this->myWords->Value("VIEWSHAREDFILES"), "module:Xmlnuke.Admin.EditLanguage?op=1");
     $this->addMenuOption($this->myWords->Value("VIEWPRIVATEFILES"), "module:Xmlnuke.Admin.EditLanguage");
     $block = new XmlBlockCollection($this->myWords->Value("WORKINGAREA"), BlockPosition::Center);
     $this->defaultXmlnukeDocument->addXmlnukeObject($block);
     $op = $this->_context->get("op");
     $ed = $this->_context->get("ed");
     $langDir = new AnydatasetLangFilenameProcessor("");
     if ($op == "") {
         $filelist = FileUtil::RetrieveFilesFromFolder($langDir->PrivatePath(), $langDir->Extension());
     } else {
         $filelist = FileUtil::RetrieveFilesFromFolder($langDir->SharedPath(), $langDir->Extension());
     }
     $it = $this->getIteratorFromList($filelist, $langDir);
     if ($this->_action == "") {
         $editlist = new XmlEditList($this->_context, $this->myWords->Value("FILELIST{$op}"), "module:Xmlnuke.Admin.EditLanguage", true, false, true, false);
         $field = new EditListField();
         $field->editlistName = "#";
         $field->fieldData = "key";
         $editlist->addEditListField($field);
         $field = new EditListField();
         $field->editlistName = "Language Filename";
         $field->fieldData = "singlename";
         $editlist->addEditListField($field);
         $editlist->setDataSource($it);
         $editlist->addParameter("op", $op);
         $editlist->setEnablePage(true);
         $editlist->setPageSize(20, 0);
         $block->addXmlnukeObject($editlist);
     } elseif ($this->_action == ModuleAction::Edit || $ed == 1) {
         if ($ed == 1) {
             $file = $this->_context->get("file");
         } else {
             $file = $this->_context->get("valueid");
         }
         $langDir = new AnydatasetLangFilenameProcessor($file);
         $langDir->setFilenameLocation($op == "" ? ForceFilenameLocation::PrivatePath : ForceFilenameLocation::SharedPath);
         $anydata = new AnyDataset($langDir->FullQualifiedNameAndPath());
         $it = $anydata->getIterator();
         $sr = $it->moveNext();
         $arFields = $sr->getFieldNames();
         $i = 0;
         $CrudFieldCollection = new CrudFieldCollection();
         foreach ($arFields as $value) {
             $process = CrudField::FactoryMinimal($value, $value, 40, $i < 4, true);
             $process->key = $i == 0;
             if ($value == "LANGUAGE") {
                 $process->beforeInsertFormatter = $this;
             }
             $CrudFieldCollection->addCrudField($process);
             $i++;
         }
         $crud = new XmlnukeCrudAnydata($this->_context, $CrudFieldCollection, $this->myWords->Value("EDITLANGUAGE", $file), "module:Xmlnuke.Admin.EditLanguage", null, $langDir);
         $crud->addParameter("op", $op);
         $crud->addParameter("ed", 1);
         $crud->addParameter("file", $file);
         $block->addXmlnukeObject($crud);
     } elseif ($this->_action == ModuleAction::Create) {
         $form = new XmlFormCollection($this->_context, "module:Xmlnuke.Admin.EditLanguage", $this->myWords->Value("NEWLANGUAGEFILE"));
         $form->addXmlnukeObject(new XmlInputHidden("action", ModuleAction::CreateConfirm));
         $form->addXmlnukeObject(new XmlInputHidden("op", $op));
         $form->addXmlnukeObject(new XmlInputTextBox($this->myWords->Value("NEWFILE"), "newfile", "", 30));
         $form->addXmlnukeObject(new XmlInputMemo($this->myWords->Value("FIELDS"), "fields", "TITLE\r\nABSTRACT"));
         $form->addXmlnukeObject(XmlInputButtons::CreateSubmitButton($this->myWords->Value("TXT_SUBMIT")));
         $block->addXmlnukeObject($form);
     } elseif ($this->_action == ModuleAction::CreateConfirm) {
         $file = $this->_context->get("newfile");
         $langDir = new AnydatasetLangFilenameProcessor($file);
         $langDir->setFilenameLocation($op == "" ? ForceFilenameLocation::PrivatePath : ForceFilenameLocation::SharedPath);
         $anydata = new AnyDataset($langDir->FullQualifiedNameAndPath());
         $fields = explode("\r\n", $this->_context->get("fields"));
         $langs = $this->_context->LanguagesAvailable();
         foreach ($langs as $lang => $dummy) {
             $anydata->appendRow();
             $anydata->addField("lang", $lang);
             foreach ($fields as $field) {
                 $anydata->addField($field, "");
             }
         }
         $anydata->Save($langDir);
         $this->_context->redirectUrl("module:Xmlnuke.Admin.EditLanguage?ed=1&file={$file}");
     }
     $langfile = $this->_context->get("langfile");
     $contents = $this->_context->get("contents");
     $contents = stripslashes($contents);
     return $this->defaultXmlnukeDocument;
 }
Ejemplo n.º 12
0
 /**
  *@desc Execute the proper action to insert, update and delete $data from database.
  *@param Context $context
  *@return IXmlnukeDocumentObject $it contains all necessary XML to inform the user the operation result
  */
 public function updateRecord()
 {
     $message = "";
     //		IXmlnukeDocumentObject $mdo
     $mdo = $this->validateUpdate();
     if ($mdo != null) {
         return $mdo;
     }
     $data = new AnyDataset($this->_anydata->FullQualifiedNameAndPath());
     if ($this->_currentAction == self::ACTION_NEW_CONFIRM) {
         $data->appendRow();
         for ($i = 0, $fieldLength = sizeof($this->_fields); $i < $fieldLength; $i++) {
             $value = $this->_context->get($this->_fields[$i]->fieldName);
             if ($this->_fields[$i]->beforeInsertFormatter != null) {
                 $value = $this->_fields[$i]->beforeInsertFormatter->Format($srCurInfo, $this->_fields[$i]->fieldName, $value);
             }
             $data->addField($this->_fields[$i]->fieldName, $value);
         }
     } else {
         $itf = $this->getIteratorFilterKey();
         $it = $data->getIterator($itf);
         if ($it->hasNext()) {
             $sr = $it->moveNext();
             if ($this->_currentAction == self::ACTION_EDIT_CONFIRM) {
                 for ($i = 0, $fieldsLength = sizeof($this->_fields); $i < $fieldsLength; $i++) {
                     $value = $this->_context->get($this->_fields[$i]->fieldName);
                     if ($this->_fields[$i]->fieldXmlInput == XmlInputObjectType::FILEUPLOAD) {
                         $files = $this->_context->getUploadFileNames();
                         if ($files[$this->_fields[$i]->fieldName] == "") {
                             continue;
                         }
                         // Do nothing if none files are uploaded.
                     }
                     if ($this->_fields[$i]->beforeInsertFormatter != null) {
                         $value = $this->_fields[$i]->beforeInsertFormatter->Format($srCurInfo, $this->_fields[$i]->fieldName, $value);
                     }
                     $sr->setField($this->_fields[$i]->fieldName, $value);
                 }
             } else {
                 if ($this->_currentAction == self::ACTION_DELETE_CONFIRM) {
                     $data->removeRow($sr);
                     // Remove the Current Row;
                 }
             }
         }
     }
     $data->Save($this->_anydata);
     //XmlFormCollection $retorno = new XmlFormCollection($this->_context, $this->_module, $message);
     //$retorno->addXmlnukeObject(new XmlInputHidden("filter", $this->_filter));
     //$retorno->addXmlnukeObject(new XmlInputHidden("sort", $this->_sort));
     //$retorno->addXmlnukeObject(new XmlInputHidden("curpage", $this->_curPage->ToString()));
     //$retorno->addXmlnukeObject(new XmlInputHidden("offset", $this->_qtdRows->ToString()));
     //XmlInputButtons btnRetorno = new XmlInputButtons();
     //btnRetorno->addSubmit("Retornar", "");
     //$retorno->addXmlnukeObject(btnRetorno);
     //		XmlParagraphCollection $retorno
     return null;
 }
Ejemplo n.º 13
0
 /**
  * Edit DataBase
  *
  */
 protected function actionEditDB()
 {
     $blockCenter = new XmlBlockCollection($this->_myWords->Value("DATABASE"), BlockPosition::Center);
     $breakline = new XmlnukeBreakLine();
     $paragraph = new XmlParagraphCollection();
     $paragraph->addXmlnukeObject(new XmlnukeText($this->_myWords->Value("DATABASETEXT")));
     $paragraph->addXmlnukeObject($breakline);
     $secop = $this->_context->get("secop");
     // Menu
     $form = new XmlFormCollection($this->_context, $this->_url . "?op=5", "Menu");
     $optionlist = array();
     $optionlist[""] = "-- Selecione --";
     $optionlist["setup"] = "Configurar a Conexão";
     $optionlist["test"] = "Testar a conexão";
     $optionlist["create"] = "Create Sample Table";
     $optionlist["edit"] = "Edit Sample Table";
     $list = new XmlEasyList(EasyListType::SELECTLIST, "secop", "Selecione a Ação", $optionlist, $secop);
     $form->addXmlnukeObject($list);
     $btnmenu = new XmlInputButtons();
     $btnmenu->addSubmit("Selecionar");
     $form->addXmlnukeObject($btnmenu);
     $blockCenter->addXmlnukeObject($form);
     // Opções:
     switch ($secop) {
         case "setup":
             $formsetup = new XmlFormCollection($this->_context, $this->_url . "?op=5", "Editar Conexão");
             $formsetup->addXmlnukeObject(new XmlInputHidden("secop", "setupconf"));
             $text = new XmlInputTextBox("Connection String", "connection", "adodriver://*****:*****@server/datasource");
             $text->setRequired(true);
             $formsetup->addXmlnukeObject($text);
             $btn = new XmlInputButtons();
             $btn->addSubmit("Salvar");
             $formsetup->addXmlnukeObject($btn);
             $blockCenter->addXmlnukeObject($formsetup);
             break;
         case "setupconf":
             $filename = new AnydatasetFilenameProcessor("_db");
             $anydata = new AnyDataset($filename->FullQualifiedNameAndPath());
             $itf = new IteratorFilter();
             $itf->addRelation("dbname", Relation::EQUAL, "sampledb");
             $it = $anydata->getIterator($itf);
             if ($it->hasNext()) {
                 $sr = $it->moveNext();
                 $sr->setField("dbtype", "dsn");
                 $sr->setField("dbconnectionstring", $this->_context->get("connection"));
             } else {
                 $anydata->appendRow();
                 $anydata->addField("dbname", "sampledb");
                 $anydata->addField("dbtype", "dsn");
                 $anydata->addField("dbconnectionstring", $this->_context->get("connection"));
             }
             $anydata->Save();
             $paragraph->addXmlnukeObject(new XmlnukeText("Updated!", true));
             break;
         case "test":
             $db = new DBDataset("sampledb");
             $db->TestConnection();
             $paragraph->addXmlnukeObject(new XmlnukeText("I suppose it is fine the connection string!", true));
             break;
         case "create":
             $db = new DBDataset("sampledb");
             $sql = "create table sample (fieldkey integer, fieldname varchar(20))";
             $db->execSQL($sql);
             $db->TestConnection();
             $paragraph->addXmlnukeObject(new XmlnukeText("Table Created!", true));
             break;
         case "edit":
             // Cria um acesso a $crud
             $pageFields = new CrudFieldCollection();
             $fieldPage = new CrudField();
             $fieldPage->fieldName = "fieldkey";
             $fieldPage->key = true;
             $fieldPage->dataType = INPUTTYPE::NUMBER;
             $fieldPage->fieldCaption = "Código";
             $fieldPage->fieldXmlInput = XmlInputObjectType::TEXTBOX;
             $fieldPage->visibleInList = true;
             $fieldPage->editable = true;
             $fieldPage->required = true;
             $fieldPage->rangeMin = "100";
             $fieldPage->rangeMax = "999";
             $pageFields->addCrudField($fieldPage);
             $fieldPage = new CrudField();
             $fieldPage->fieldName = "fieldname";
             $fieldPage->key = false;
             $fieldPage->dataType = INPUTTYPE::TEXT;
             $fieldPage->fieldCaption = "Name";
             $fieldPage->fieldXmlInput = XmlInputObjectType::TEXTBOX;
             $fieldPage->visibleInList = true;
             $fieldPage->editable = true;
             $fieldPage->required = true;
             $fieldPage->maxLength = 20;
             $pageFields->addCrudField($fieldPage);
             $crud = new XmlnukeCrudDB($this->_context, $pageFields, "Edição teste usando Banco de Dados", $this->_url . "?op=5", null, "sample", "sampledb");
             $crud->setPageSize(3, 0);
             $crud->addParameter("secop", "edit");
             $paragraph->addXmlnukeObject($crud);
             break;
     }
     $blockCenter->addXmlnukeObject($paragraph);
     $this->_document->addXmlnukeObject($blockCenter);
 }