예제 #1
0
파일: ManagePoll.php 프로젝트: byjg/xmlnuke
 /**
  * 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);
     }
 }
예제 #2
0
 /**
  * Process Vote. Note that the system ONLY process the vote if there is no another equal IP.
  *
  * @param int $width
  * @param int $height
  */
 public function processVote($width = 450, $height = 400)
 {
     if ($this->_context->get("xcrt") == "") {
         // Is The Post values needed to process vote exists?
         if ($this->_context->get("xmlnuke_poll") != "" && $this->_context->get("xmlnuke_polllang") != "" && $this->_context->get("xmlnuke_pollanswer") != "") {
             $this->_poll = $this->_context->get("xmlnuke_poll");
             $this->_lang = $this->_context->get("xmlnuke_polllang");
             $ok = true;
             // Check if IP already voted -> Freeze IP for 5 days.
             if ($this->_isdb) {
                 // Remove Old Entries
                 $dbdata = new DBDataset($this->_connection);
                 $sql = "delete from :table where register < now() - interval 5 day ";
                 $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip));
                 $dbdata->execSQL($sql);
                 // Check if exists
                 $sql = "select count(1) from :table where ip = [[ip]] and name = [[name]] ";
                 $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip));
                 $param = array("ip" => $this->_context->getClientIp(), "name" => $this->_poll);
                 $count = $dbdata->getScalar($sql, $param);
                 $ok = false;
                 if ($count == 0) {
                     $ok = true;
                     $sql = "insert into :table (ip, name, register) values ([[ip]], [[name]], now()) ";
                     $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip));
                     $param = array("ip" => $this->_context->getClientIp(), "name" => $this->_poll);
                     try {
                         $dbdata->execSQL($sql, $param);
                     } catch (\PDOException $ex) {
                         $ok = false;
                     }
                 }
             }
             // Is My IP Unique? If true I can process the vote.
             // Note if the poll name, lang and code are wrong the system does not do anything.
             if ($ok) {
                 // Get Data
                 $itf = new IteratorFilter();
                 $itf->addRelation("name", Relation::EQUAL, $this->_poll);
                 $itf->addRelation("lang", Relation::EQUAL, $this->_lang);
                 $itf->addRelation("code", Relation::EQUAL, $this->_context->get("xmlnuke_pollanswer"));
                 if ($this->_isdb) {
                     $dbdata = new DBDataset($this->_connection);
                     $param = array();
                     $sql = "update :table set votes = IFNULL(votes,0) + 1 where :filter ";
                     $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tblanswer, ':filter' => $itf->getFilter(IteratorFilter::SQL, $param)));
                     $dbdata->execSQL($sql, $param);
                 } else {
                     $this->getAnyData();
                     $itAnswer = $this->_anyAnswer->getIterator($itf);
                     if ($itAnswer->hasNext()) {
                         $sr = $itAnswer->moveNext();
                         $sr->setField("votes", intval($sr->getField("votes")) + 1);
                         $this->_anyAnswer->Save();
                     }
                 }
             }
             $this->_processed = true;
         }
     } else {
         $this->_processed = true;
     }
     $this->_width = $width;
     $this->_height = $height;
 }
예제 #3
0
파일: Context.php 프로젝트: byjg/xmlnuke
 /**
  * @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);
 }
예제 #4
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;
 }
예제 #5
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;
 }
예제 #6
0
파일: Sample.php 프로젝트: byjg/xmlnuke
 /**
  * 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);
 }