/** * Main zTag functions selector * * <code> * zvar_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zvar_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strId = $arrParam["id"]; $strUse = $arrParam["use"]; $strVar = $arrParam["var"]; $strValue = $arrParam["value"]; $strTransform = $arrParam["transform"]; if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = $arrayTag[$tagId][ztagContent]; } $errorMessage = ""; switch (strtolower($tagFunction)) { /*+ * Creates a $var with it's value * * <code> * <zvar:set id="someVar" value="someValue" /> * * <zvar:set id="otherVar"> * It's value * </zvar:set> * </code> * * @param string id="someVar" Unique Id for the new variable $varName * @param string value="someValue" Value to b saved into this variable */ case "set": if ($arrayTag[$tagId][ztagContentWidth]) { $strValue = ztagVars($arrayTag[$tagId][ztagContent], $arrayTagId); $arrParam["value"] = $strValue; } if (strlen($strVar)) { $strId = $strVar; $arrParam["id"] = $strId; } $errorMessage .= ztagParamCheck($arrParam, "value,id"); if (strlen($strTransform)) { $strValue = ztagTransform($strValue, $strTransform); } $arrayTagId["\$" . $strId][ztagIdValue] = $strValue; $arrayTagId["\$" . $strId][ztagIdLength] = strlen($strValue); $arrayTagId["\$" . $strId][ztagIdType] = idTypeFVar; break; /*+ * Creates an array var $someArray with it´s formated content * * <code> * <zvar:setarray id="someArray"> * "index"="value" * , "index2":"value 2" * , 'index3'=>'value 3' * , 99="value" * , "indexn"=99 * </znosql:setarray> * * <zvar:setarray id="someArray" value="'index'='value',9='value'" /> * </code> * * @param string id="someArray" Unique Id for the new variable $varName */ /*+ * Creates an array var $someArray with it´s formated content * * <code> * <zvar:setarray id="someArray"> * "index"="value" * , "index2":"value 2" * , 'index3'=>'value 3' * , 99="value" * , "indexn"=99 * </znosql:setarray> * * <zvar:setarray id="someArray" value="'index'='value',9='value'" /> * </code> * * @param string id="someArray" Unique Id for the new variable $varName */ case "setarray": if (strlen($strContent)) { $contentArray = $strContent; } if (strlen($strValue)) { $contentArray = $strValue; } if ($contentArray) { $contentArray = ztagVars($contentArray, $arrayTagId); $arrParam["value"] = $strValue; } if (!strlen($strContent) && !strlen($strValue)) { $errorMessage .= ztagParamCheck($arrParam, "id,value"); } if ($strTransform && $contentArray) { $contentArray = ztagTransform($contentArray, $strTransform); } $contentArray = ltrim($contentArray, "\r\n"); $contentArray = rtrim($contentArray, "\r\n"); preg_match_all('%\\s*,?\\s*(?P<index>"[^"]*?"|\'[^\']*?\'|\\d+)\\s*(:|=|=>)\\s*(?P<value>"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|\\d+)%', $contentArray, $Matches, PREG_OFFSET_CAPTURE); $arrayContent = array(); foreach ($Matches[0] as $key => $value) { $paramKey = $Matches["index"][$key][0]; $paramValue = $Matches["value"][$key][0]; $patternString = '%^(["\'])(.*?)\\1%'; $paramKey = preg_replace($patternString, "\$2", $paramKey); $paramValue = preg_replace($patternString, "\$2", $paramValue); $arrayContent[$paramKey] = preg_replace('%\\\\([\'"])%', "\$1", $paramValue); } $arrayTagId["\$" . $strId][ztagIdValue] = $arrayContent; $arrayTagId["\$" . $strId][ztagIdLength] = count($arrayContent); $arrayTagId["\$" . $strId][ztagIdType] = idTypeFVar; break; /*+ * Creates a $var if the contidion is made with it´s value * * <code> * <zvar:setif use="getFiltro" equal="nome" var="sqlSelect" then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')" /> * * <zvar:setif use="CO_CPF" condition="empty()" var="sqlSelect" then="CO_CPF LIKE '%$CO_CPF%'" /> * </code> * * @param string use="getFiltro" * @param string equal="nome" * @param string var="sqlSelect" * @param string then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')" */ /*+ * Creates a $var if the contidion is made with it´s value * * <code> * <zvar:setif use="getFiltro" equal="nome" var="sqlSelect" then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')" /> * * <zvar:setif use="CO_CPF" condition="empty()" var="sqlSelect" then="CO_CPF LIKE '%$CO_CPF%'" /> * </code> * * @param string use="getFiltro" * @param string equal="nome" * @param string var="sqlSelect" * @param string then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')" */ case "setif": $strEqual = $arrParam["equal"]; $strNotEqual = $arrParam["notequal"]; $strThen = $arrParam["then"]; $strElse = $arrParam["else"]; $strCondition = $arrParam["condition"]; $strNotCondition = $arrParam["notcondition"]; $errorMessage .= ztagParamCheck($arrParam, "use,then,var"); if ($strUse) { $strUse = $arrayTagId["\$" . $strUse][ztagIdValue]; } if ($strEqual) { if ($strUse == $strEqual) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen; } else { if ($strElse) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse; } } } if ($strNotEqual) { if ($strUse != $strNotEqual) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen; } else { if ($strElse) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse; } } } if ($strCondition) { $strCondition = ztagTransform($strUse, $strCondition); if ($strCondition) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen; } else { if ($strElse) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse; } } } if ($strNotCondition) { $strNotCondition = ztagTransform($strUse, $strNotCondition); if (!$strNotCondition) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen; } else { if ($strElse) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse; } } } break; /*+ * Unset a variable * * <code> * <zvar:unset use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Unset a variable * * <code> * <zvar:unset use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "unset": /*+ * Reset a variable * * <code> * <zvar:reset use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Reset a variable * * <code> * <zvar:reset use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "reset": $errorMessage = ztagParamCheck($arrParam, "use"); if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) { $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!"; } $arrayTagId["\$" . $strUse] = array(); break; /*+ * Update a $var with it's value * * <code> * <zvar:update use="someVar" value="someValue" /> * * <zvar:set use="otherVar"> * It's value * </zvar:set> * </code> * * @param string use="someVar" Unique Id of a variable $varName * @param string value="someValue" Value to b saved into this variable */ /*+ * Update a $var with it's value * * <code> * <zvar:update use="someVar" value="someValue" /> * * <zvar:set use="otherVar"> * It's value * </zvar:set> * </code> * * @param string use="someVar" Unique Id of a variable $varName * @param string value="someValue" Value to b saved into this variable */ case "update": if ($arrayTag[$tagId][ztagContentWidth]) { $strValue = ztagVars($arrayTag[$tagId][ztagContent], $arrayTagId); $arrParam["value"] = $strValue; } $errorMessage .= ztagParamCheck($arrParam, "value,use"); if (strlen($strUse)) { $arrayTagId["\$" . $strUse][ztagIdValue] = $strValue; $arrayTagId["\$" . $strUse][ztagIdLength] = strlen($strValue); $arrayTagId["\$" . $strUse][ztagIdType] = idTypeFVar; } break; /*+ * Get and return a variable value * * <code> * <zvar:get use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Get and return a variable value * * <code> * <zvar:get use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "get": /*+ * Show variable value * * <code> * <zvar:show use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Show variable value * * <code> * <zvar:show use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "show": $errorMessage .= ztagParamCheck($arrParam, "use"); preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE); if (count($Matches[0][0])) { $var = $Matches["var"][0][0]; $index = $Matches["index"][0][0]; $varValue = $arrayTagId["\$" . $var][ztagIdValue]; $varValue = $varValue[$index]; } else { if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) { $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!"; } $varValue = $arrayTagId["\$" . $strUse][ztagIdValue]; } if (strlen($strTransform)) { $varValue = ztagTransform($varValue, $strTransform); } $arrayTag[$tagId][ztagResult] = $varValue; break; /*+ * Creates a $arrayVar for var parameters, applying the pattern using use var content. * * <code> * <zvar:regex pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%' use="urlAssunto" var="arrayAssunto" /> * </code> * * @param string pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%' * @param string use="urlAssunto" * @param string value="$arrayValue" * @param string var="arrayAssunto" * @param string error="errorVar" */ /*+ * Creates a $arrayVar for var parameters, applying the pattern using use var content. * * <code> * <zvar:regex pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%' use="urlAssunto" var="arrayAssunto" /> * </code> * * @param string pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%' * @param string use="urlAssunto" * @param string value="$arrayValue" * @param string var="arrayAssunto" * @param string error="errorVar" */ case "regex": $strPattern = $arrParam["pattern"]; $strError = $arrParam["error"]; $errorMessage .= ztagParamCheck($arrParam, "pattern,var"); if ($strUse) { $strValue = $arrayTagId["\$" . $strUse][ztagIdValue]; } preg_match_all($strPattern, $strValue, $Matches, PREG_SET_ORDER); $arrayResult = array(); foreach ($Matches as $keyMatches => $valueMatches) { foreach ($valueMatches as $key => $value) { if (is_string($key) || $key) { $arrayMatches[$key] = $value; } } $arrayResult[] = $arrayMatches; } if (preg_last_error() && strlen($strError)) { $arrayTagId["\$" . $strError][ztagIdValue] = preg_last_error(); $arrayTagId["\$" . $strError][ztagIdLength] = count(preg_last_error()); $arrayTagId["\$" . $strError][ztagIdType] = idTypeFVar; } else { $arrayTagId["\$" . $strError] = array(); } if (strlen($strVar) && count($arrayResult)) { $arrayTagId["\$" . $strVar][ztagIdValue] = $arrayResult; $arrayTagId["\$" . $strVar][ztagIdLength] = count($arrayResult); $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar; } else { $arrayTagId["\$" . $strVar] = array(); } break; /*+ * Decrement a variable value * * <code> * <zvar:decrement use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Decrement a variable value * * <code> * <zvar:decrement use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "decrement": /*+ * Decrement a variable value * * <code> * <zvar:dec use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Decrement a variable value * * <code> * <zvar:dec use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "dec": $errorMessage .= ztagParamCheck($arrParam, "use"); preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE); if (count($Matches[0][0])) { $var = $Matches["var"][0][0]; $index = $Matches["index"][0][0]; $varValue = $arrayTagId["\$" . $var][ztagIdValue]; $arrayTagId["\$" . $var][ztagIdValue] = $varValue[$index]--; } else { if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) { $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!"; } $arrayTagId["\$" . $strUse][ztagIdValue]--; } break; /*+ * Increment a variable value * * <code> * <zvar:increment use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Increment a variable value * * <code> * <zvar:increment use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "increment": /*+ * Increment a variable value * * <code> * <zvar:inc use="getFiltro" /> * </code> * * @param string use="getFiltro" */ /*+ * Increment a variable value * * <code> * <zvar:inc use="getFiltro" /> * </code> * * @param string use="getFiltro" */ case "inc": $errorMessage .= ztagParamCheck($arrParam, "use"); preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE); if (count($Matches[0][0])) { $var = $Matches["var"][0][0]; $index = $Matches["index"][0][0]; $varValue = $arrayTagId["\$" . $var][ztagIdValue]; $arrayTagId["\$" . $var][ztagIdValue] = $varValue[$index]++; } else { if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) { $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!"; } $arrayTagId["\$" . $strUse][ztagIdValue]++; } break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }
/** * Main zTag functions selector * * <code> * zheader_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zheader_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strUse = $arrParam["use"]; $strValue = $arrParam["value"]; $errorMessage = ""; $tagValue = $arrayTagId[$strParam][ztagIdValue]; switch (strtolower($tagFunction)) { /*+ * Location IF * * <code> * <zheader:locationif use="!userLogged" notcondition="nome" value="/logOn.php" /> * </code> * * @param string use="!userLogged" * @param string notcondition="nome" * @param string value="/logOn.php" * * @author Ruben Zevallos Jr. <*****@*****.**> */ case "locationif": // @TODO Rever esta Função, criando algo mais genérico $strEqual = $arrParam["equal"]; $strNotEqual = $arrParam["notequal"]; $strCondition = $arrParam["condition"]; $strNotCondition = $arrParam["notcondition"]; // header("Location: /logOn.php"); $errorMessage .= ztagParamCheck($arrParam, "use,value"); if ($strEqual) { if ($strUse == $strEqual) { header("Location: {$strValue}"); } } if ($strNotEqual) { if ($strUse != $strNotEqual) { header("Location: {$strValue}"); } } if ($strCondition) { $strCondition = ztagTransform($strUse, $strCondition); if ($strCondition) { header("Location: {$strValue}"); } } if ($strNotCondition) { $strNotCondition = ztagTransform($strUse, $strNotCondition); if (!$strNotCondition) { header("Location: {$strValue}"); } } break; /*+ * Location * * <code> * <zheader:location value="/logOn.php" /> * </code> * * @param string value="/logOn.php" * * @author Ruben Zevallos Jr. <*****@*****.**> */ /*+ * Location * * <code> * <zheader:location value="/logOn.php" /> * </code> * * @param string value="/logOn.php" * * @author Ruben Zevallos Jr. <*****@*****.**> */ case "location": // header("Location: /logOn.php"); $errorMessage .= ztagParamCheck($arrParam, "value"); if (strlen($strValue)) { header("Location: {$strValue}"); } break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } /* debugError("tagFunction=$tagFunction" ."<br />tagId=$tagId" ."<br />strId=$strId" ."<br />strUse=$strUse" ."<br />strValue=$strValue" ."<br />arrayTagId[$strId][ztagIdValue]=".$arrayTagId[$strId][ztagIdValue] ."<br />arrayTagId[$strUse][ztagIdValue]=".$arrayTagId[$strUse][ztagIdValue] ."<br />arrayTag[$tagId][ztagResult]=".$arrayTag[$tagId][ztagResult]); */ ztagError($errorMessage, $arrayTag, $tagId); }
/** * Main zTag functions selector * * <code> * zpost_zexecute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zpost_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strName = $arrParam["name"]; $strVar = $arrParam["var"]; $strTransform = $arrParam["transform"]; if ($strName) { $strPostValue = $_POST[$strName]; } $errorMessage = ""; switch (strtolower($tagFunction)) { /*+ * Get * * <code> * <zdoc:get name="string" var="string" /> * </code> * * @param name="string" * @param var="string" * * @author Ruben Zevallos Jr. <*****@*****.**> */ case "get": $errorMessage .= ztagParamCheck($arrParam, "name,var"); if ($strTransform) { $strPostValue = ztagTransform($strPostValue, $strTransform); } if ($strVar) { $arrayTagId["\$" . $strVar][ztagIdValue] = $strPostValue; $arrayTagId["\$" . $strVar][ztagIdType] = idTypePost; } if (isset($strPostValue)) { $arrayTag[$tagId][ztagValue] = $strPostValue; } break; /*+ * Show * * <code> * <zdoc:show name="string" /> * </code> * * @param name="string" * * @author Ruben Zevallos Jr. <*****@*****.**> */ /*+ * Show * * <code> * <zdoc:show name="string" /> * </code> * * @param name="string" * * @author Ruben Zevallos Jr. <*****@*****.**> */ case "show": $errorMessage = ztagParamCheck($arrParam, "name"); if ($strTransform) { $strPostValue = ztagTransform($strPostValue, $strTransform); } if (isset($strPostValue)) { $arrayTag[$tagId][ztagResult] = $strPostValue; } break; default: $strMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }
/** * Main zTag functions selector * * <code> * zdbal_zexecute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zdbal_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { global $dbHandleDefault; $arrParam = $arrayTag[$tagId][ztagParam]; $strId = $arrParam["id"]; $strUpdate = $arrParam["update"]; $strDriver = $arrParam["driver"]; $strHost = $arrParam["host"]; $strDatabase = $arrParam["database"]; $strUser = $arrParam["user"]; $strPassword = $arrParam["password"]; $strFilename = $arrParam["filename"]; $strMode = $arrParam["mode"]; $strUse = $arrParam["use"]; $strName = $arrParam["name"]; $strVar = $arrParam["var"]; $strTransform = $arrParam["transform"]; $errorMessage = ""; switch (strtolower($tagFunction)) { /*+ * Open a database connection to defined driver and parameters * * <code> * <zdbal:open id="mysqlConn" driver="mysql" host="#mysqlHost" database="#mysqlDatabase" user="******" password="******" charset="utf8"/> * * <zdbal:open id="sqliteConn" driver="sqlite" filename="/ZTag/SQLite.db" /> * </code> * * @param string id="MySQL Handle Id" * @param string driver="mssql|mysql|pgsql|sqlite|firebird" * @param string host="Host" * @param string database="Database name" * @param string user="******" * @param string password="******" * @param string port="8023" * @param string socket="socket" * @param string charset="utf8" */ case 'open': $strCharset = $arrParam['charset']; $strPort = $arrParam['port']; $strSocket = $arrParam['charset']; $dbalDriver = constant("dbal{$strDriver}"); if (strlen($strHost)) { ztagReturnConstant($strHost); } if (strlen($strDatabase)) { ztagReturnConstant($strDatabase); } if (strlen($strUser)) { ztagReturnConstant($strUser); } if (strlen($strPassword)) { ztagReturnConstant($strPassword); } $dbalConfig = new \Doctrine\DBAL\Configuration(); $dbalParams = array('dbname' => $strDatabase, 'user' => $strUser, 'password' => $strPassword, 'host' => $strHost, 'driver' => $dbalDriver); /* Connect to the database */ $dbHandle = \Doctrine\DBAL\DriverManager::getConnection($dbalParams); if ($errorMessage) { $errorMessage .= "<br />{$strDriver}{$errorMessage}"; } $arrayTagId[$strId][ztagIdHandle] = $dbHandle; $arrayTagId[$strId][ztagIdType] = idTypeDBAL; $arrayTagId[$strId][ztagIdState] = idStateOpened; break; /*+ * Close the Database connection openned with Id. * * <code> * <zdbal:close use="mysqlConn" /> * </code> * * @param string use="mysqlConn" */ /*+ * Close the Database connection openned with Id. * * <code> * <zdbal:close use="mysqlConn" /> * </code> * * @param string use="mysqlConn" */ case 'close': $errorMessage .= ztagParamCheck($arrParam, "use"); $arrayTagId[$strUse][ztagIdHandle]->close(); $arrayTagId[$strUse][ztagIdState] = idStateClosed; break; /*+ * Set a SQL query to use with another zdbal Tag. * * <code> * <zdbal:query use="ociConn" id="ociQuery"> * SELECT US.NM_USUARIO userLogin * , P.NM_PESSOA userName * , P.CD_PESSOA userId * , US.CD_SESSAO_LOGIN userLoginLast * , US.CD_SESSAO_LOGIN_ERRO userLoginError * , US.NU_LOGIN_ERROS userLoginErrors * , to_char(US.DT_LOGIN_BLOQUEIO,'yyyy/mm/dd hh24:mi:ss') userLoginBlocked * FROM TB_USUARIO_SISTEMA US * LEFT JOIN TB_PESSOA P ON US.CD_PESSOA_USUARIO = P.CD_PESSOA * AND FL_ATIVO = 'S' * </zdbal:query> * </code> * * @param string use="ociConn" The Id Handle from a Open zdbal tag * @param string id="ociQuery" Id where the Query will be saved * @param string update="ociQuery" Id to be updated */ /*+ * Set a SQL query to use with another zdbal Tag. * * <code> * <zdbal:query use="ociConn" id="ociQuery"> * SELECT US.NM_USUARIO userLogin * , P.NM_PESSOA userName * , P.CD_PESSOA userId * , US.CD_SESSAO_LOGIN userLoginLast * , US.CD_SESSAO_LOGIN_ERRO userLoginError * , US.NU_LOGIN_ERROS userLoginErrors * , to_char(US.DT_LOGIN_BLOQUEIO,'yyyy/mm/dd hh24:mi:ss') userLoginBlocked * FROM TB_USUARIO_SISTEMA US * LEFT JOIN TB_PESSOA P ON US.CD_PESSOA_USUARIO = P.CD_PESSOA * AND FL_ATIVO = 'S' * </zdbal:query> * </code> * * @param string use="ociConn" The Id Handle from a Open zdbal tag * @param string id="ociQuery" Id where the Query will be saved * @param string update="ociQuery" Id to be updated */ case 'query': $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = ztagVars($arrayTag[$tagId][ztagContent], $arrayTagId); if (!strlen($strId)) { $errorMessage .= ztagParamCheck($arrParam, "update"); $strId = $strUpdate; } else { $errorMessage .= ztagParamCheck($arrParam, "id"); } // $dbStatement = $arrayTagId[$strUse][ztagIdHandle]->prepare($strContent); if ($strId) { $arrayTagId[$strId][ztagIdValue] = $strContent; $arrayTagId[$strId][ztagIdLength] = strlen($strContent); $arrayTagId[$strId][ztagIdType] = idTypeQuery; $arrayTagId[$strId][ztagIdHandle] = $arrayTagId[$strUse][ztagIdHandle]; } } else { $errorMessage .= "<br />Tag Query cannot be empty!"; } break; /*+ * Return TRUE if the current record is at the first * * <code> * <zdbal:bof use="mysqlConn" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zdbal tag */ /*+ * Return TRUE if the current record is at the first * * <code> * <zdbal:bof use="mysqlConn" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zdbal tag */ case "bof": $errorMessage .= ztagParamCheck($arrParam, "use"); $arrayTag[$tagId][ztagResult] = dbBOF($arrayTagId[$strUse][ztagIdHandle]); break; /*+ * Return TRUE if the current record is at the first * * <code> * <zdbal:eof use="mysqlConn" /> * </code> * * use="mysqlConn" - The Id Handle from a Open zdbal tag */ /*+ * Return TRUE if the current record is at the first * * <code> * <zdbal:eof use="mysqlConn" /> * </code> * * use="mysqlConn" - The Id Handle from a Open zdbal tag */ case "eof": $errorMessage .= ztagParamCheck($arrParam, "use"); $arrayTag[$tagId][ztagResult] = dbEOF($arrayTagId[$strUse][ztagIdHandle]); break; /*+ * Return TRUE if the current record is at the first * * <code> * <zdbal:field use="mysqlConn" name="NM_NOME" /> * * Or * * <zdbal:field name="NM_NOME" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zdbal tag */ /*+ * Return TRUE if the current record is at the first * * <code> * <zdbal:field use="mysqlConn" name="NM_NOME" /> * * Or * * <zdbal:field name="NM_NOME" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zdbal tag */ case "field": if ($intFather = $arrayTag[$tagId][ztagFather]) { $arrParam["use"] = "Field_{$intFather}"; } // echo "<br />intFather=$intFather"; $errorMessage .= ztagParamCheck($arrParam, "use,name"); $dbHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandleValue = $dbHandle[dbHandleFetch][$strName]; if ($strTransform) { $dbHandleValue = ztagTransform($dbHandleValue, $strTransform); } if ($strVar) { $arrayTagId['$' . $strVar][ztagIdValue] = $dbHandleValue; $arrayTagId['$' . $strVar][ztagIdType] = idTypeField; } $arrayTag[$tagId][ztagResult] = $dbHandleValue; break; /*+ * FieldVar * * <code> * <zdbal:fieldvar use="mysqlConn" name="NM_NOME" var="$NM_NOME" /> * </code> * * @param string use="mysqlConn" The Id Handle from a Open zdbal tag * @param string name="NM_NOME" * @param string var="$NM_NOME" */ /*+ * FieldVar * * <code> * <zdbal:fieldvar use="mysqlConn" name="NM_NOME" var="$NM_NOME" /> * </code> * * @param string use="mysqlConn" The Id Handle from a Open zdbal tag * @param string name="NM_NOME" * @param string var="$NM_NOME" */ case "fieldvar": $errorMessage .= ztagParamCheck($arrParam, "use,name,var"); $dbHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandleValue = $dbHandle[dbHandleFetch][$strName]; if ($strTransform) { $dbHandleValue = ztagTransform($dbHandleValue, $strTransform); } if ($strVar) { $arrayTagId['$' . $strVar][ztagIdValue] = $dbHandleValue; $arrayTagId['$' . $strVar][ztagIdType] = idTypeField; } break; /*+ * Prepare * * <code> * <zdbal:prepare conn="oracleConn" use="oracleQuery" /> * </code> * * @param string conn="oracleConn" * @param string use="oracleQuery" */ /*+ * Prepare * * <code> * <zdbal:prepare conn="oracleConn" use="oracleQuery" /> * </code> * * @param string conn="oracleConn" * @param string use="oracleQuery" */ case "prepare": $errorMessage .= ztagParamCheck($arrParam, "use,conn"); $dbHandle = $arrayTagId[$strConn][ztagIdHandle]; $dbQuery = $arrayTagId[$strUse][ztagIdValue]; dbPrepare($dbHandle, $dbQuery); break; /*+ * Prepare * * <code> * <zdbal:param use="query002" param="P_CD_PESSOA_USUARIO" var="" type="PARAM_INT" /> * </code> * * @param string use="query002" * @param string param="P_CD_PESSOA_USUARIO" * @param string var="" * @param string type="PARAM_INT" */ /*+ * Prepare * * <code> * <zdbal:param use="query002" param="P_CD_PESSOA_USUARIO" var="" type="PARAM_INT" /> * </code> * * @param string use="query002" * @param string param="P_CD_PESSOA_USUARIO" * @param string var="" * @param string type="PARAM_INT" */ case "param": $errorMessage .= ztagParamCheck($arrParam, "id,value"); $arrayTagId[$strId][ztagIdValue] = $strValue; $arrayTagId[$strId][ztagIdLength] = strlen($strValue); $arrayTagId[$strId][ztagIdType] = idTypeFVar; break; /*+ * Create * * <code> * <zdbal:create use="query002" /> * </code> * * @param string use="query002" */ /*+ * Create * * <code> * <zdbal:create use="query002" /> * </code> * * @param string use="query002" */ case "create": $errorMessage .= ztagParamCheck($arrParam, "id"); if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = $arrayTag[$tagId][ztagContent]; $arrayTagId[$strId][ztagIdValue] = $strContent; $arrayTagId[$strId][ztagIdLength] = strlen($strContent); } break; /*+ * Show * * <code> * <zdbal:show use="query002" /> * </code> * * @param string use="query002" */ /*+ * Show * * <code> * <zdbal:show use="query002" /> * </code> * * @param string use="query002" */ case "show": $errorMessage .= ztagParamCheck($arrParam, "use"); $arrayTag[$tagId][ztagResult] = $arrayTagId[$strUse][ztagIdValue]; break; /*+ * List the available databases for this connection * * <code> * <zdbal:listdatabases use="myConn" var="myTables"/> * </code> * * @param string use="myConn" * @param string var="myTables" */ /*+ * List the available databases for this connection * * <code> * <zdbal:listdatabases use="myConn" var="myTables"/> * </code> * * @param string use="myConn" * @param string var="myTables" */ case 'listdatabases': $errorMessage .= ztagParamCheck($arrParam, 'use,var'); $smHandle = $arrayTagId[$strUse][ztagIdHandle]->getSchemaManager(); if (strlen($strVar)) { $arrayTagId['$' . $strVar][ztagIdValue] = $smHandle->listDatabases(); $arrayTagId['$' . $strVar][ztagIdType] = idTypeFVar; } // echo "<br /><pre>".print_r( $arrayTagId['$'.$strVar][ztagIdValue], 1); break; /*+ * List the tables for the connection * * <code> * <zdbal:listtables use="myConn" var="myTables"/> * </code> * * @param string use="myConn" * @param string var="myTables" */ /*+ * List the tables for the connection * * <code> * <zdbal:listtables use="myConn" var="myTables"/> * </code> * * @param string use="myConn" * @param string var="myTables" */ case 'listtables': $errorMessage .= ztagParamCheck($arrParam, 'use,var'); $smHandle = $arrayTagId[$strUse][ztagIdHandle]->getSchemaManager(); if (strlen($strVar)) { $arrayTagId['$' . $strVar][ztagIdValue] = $smHandle->listTableNames(); $arrayTagId['$' . $strVar][ztagIdType] = idTypeFVar; } // echo "<br /><pre>".print_r( $arrayTagId['$'.$strVar][ztagIdValue], 1); break; /*+ * Return a list of all tables in the current database * * <code> * <zdbal:listtablenames use="myConn" var="myTables"/> * </code> * * @param string use="myConn" * @param string var="myTables" */ /*+ * Return a list of all tables in the current database * * <code> * <zdbal:listtablenames use="myConn" var="myTables"/> * </code> * * @param string use="myConn" * @param string var="myTables" */ case 'listtablenames': $errorMessage .= ztagParamCheck($arrParam, "use,var"); $smHandle = $arrayTagId[$strUse][ztagIdHandle]->getSchemaManager(); if (strlen($strVar)) { $arrayTagId['$' . $strVar][ztagIdValue] = $smHandle->listTableNames(); $arrayTagId['$' . $strVar][ztagIdType] = idTypeFVar; } // echo "<br /><pre>".print_r( $arrayTagId['$'.$strVar][ztagIdValue], 1); break; /*+ * List the columns for a given table. * * <code> * <zdbal:listtablecolumns use="myConn" table="tableName" var="myColumns"/> * </code> * * @param string use="myConn" * @param string table="tableName" * @param string var="myColumns" */ /*+ * List the columns for a given table. * * <code> * <zdbal:listtablecolumns use="myConn" table="tableName" var="myColumns"/> * </code> * * @param string use="myConn" * @param string table="tableName" * @param string var="myColumns" */ case 'listtablecolumns': $strTable = $arrParam["table"]; $errorMessage .= ztagParamCheck($arrParam, "use,table,var"); $smHandle = $arrayTagId[$strUse][ztagIdHandle]->getSchemaManager(); if (strlen($strVar) && strlen($strTable)) { $tableHandle = $smHandle->listTableColumns($strTable); foreach ($tableHandle as $key => $value) { $tableValue[$key]['type'] = $value->getType()->getName(); $tableValue[$key]['fixed'] = $value->getFixed(); $tableValue[$key]['lenght'] = $value->getLength(); $tableValue[$key]['precision'] = $value->getPrecision(); $tableValue[$key]['scale'] = $value->getScale(); $tableValue[$key]['unsigned'] = $value->getUnsigned(); $tableValue[$key]['notnull'] = $value->getNotnull(); $tableValue[$key]['autoincrement'] = $value->getAutoincrement(); $tableValue[$key]['default'] = $value->getDefault(); // $tableValue[$key]['comment'] = $value->getComment(); } $arrayTagId['$' . $strVar][ztagIdValue] = $tableValue; $arrayTagId['$' . $strVar][ztagIdType] = idTypeFVar; } // echo "<br /><pre>".print_r( $arrayTagId['$'.$strVar][ztagIdValue], 1); break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }
function ztagtemplatefile_test($tagId, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strValue = $arrParam["value"]; $strVar = $arrParam["var"]; $templateContent = $arrayTag[$tagId][ztagContent]; if ($strContent) { if ($strTransform) { $strContent = ztagTransform($strContent, $strTransform); } $arrayTag[$tagId][ztagResult] = "<b>{$strContent}</b>"; } if ($strValue) { if ($strTransform) { $strValue = ztagTransform($strValue, $strTransform); } $arrayTag[$tagId][ztagResult] = "<u>{$strValue}</u>"; } if ($strVar) { if ($strTransform) { $strVar = ztagTransform($strVar, $strTransform); } $arrayTag[$tagId][ztagResult] = "<i>{$strVar}</i>"; } else { if (!$strContent && !$strValue) { $errorMessage .= ztagParamCheck($arrParam, "value"); } } }
/** * Main zTag functions selector * * <code> * zemanuel_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zemanuel_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strValue = $arrParam["value"]; $strVar = $arrParam["var"]; $strTransform = $arrParam["transform"]; if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = $arrayTag[$tagId][ztagContent]; } $errorMessage = ""; switch (strtolower($tagFunction)) { // <zemanuel:open id="mysqlConn" driver="mysql" host="@@mysqlHost" database="@@mysqlDatabase" user="******", password="******" /> // <zemanuel:open id="sqliteConn" driver="sqlite" filename="/ZTag/SQLite.db" /> case "oi": // echo "<pre>".print_r($arrayTag[$tagId], 1)."</pre>"; if ($strContent) { if ($strTransform) { $strContent = ztagTransform($strContent, $strTransform); } $arrayTag[$tagId][ztagResult] = "<b>{$strContent}</b>"; } if ($strValue) { if ($strTransform) { $strValue = ztagTransform($strValue, $strTransform); } $arrayTag[$tagId][ztagResult] = "<u>{$strValue}</u>"; } if ($strVar) { if ($strTransform) { $strVar = ztagTransform($strVar, $strTransform); } $arrayTag[$tagId][ztagResult] = "<i>{$strVar}</i>"; } else { if (!$strContent && !$strValue) { $errorMessage .= ztagParamCheck($arrParam, "value"); } } break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }
/** * Main zTag functions selector * * <code> * zcode_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zcode_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strValue = $arrParam["value"]; $strVar = $arrParam["var"]; $strTransform = $arrParam["transform"]; $strTitle = $arrParam["title"]; if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = $arrayTag[$tagId][ztagContent]; } $errorMessage = ""; switch (strtolower($tagFunction)) { /*+ * Present in a code way of values content * * * Return the variable content in a formated code * Teste line * * * <code> * <zcode:show value="$templateValue" title="$templateFile" /> * </code> * * @param string value="$templateValue" * @param string title="$templateFile" * * @param string dir="string" Full directory where the zTag .inc.php files are * * @return array Return an array with all docs and functions * * @since 0.0.2 ALFA * * @see zctrl:if * * @uses zvar:set * * @copyright 2010 by Ruben Zevallos(r) Jr. * * @author Ruben Zevallos Jr. <*****@*****.**> */ case "show": // echo "<pre>".print_r($arrayTag[$tagId], 1)."</pre>"; if ($strContent) { $contentHTML = $strContent; } if ($strValue) { $contentHTML = $strValue; } if ($strVar) { $contentHTML = $strVar; } else { if (!$strContent && !$strValue) { $errorMessage .= ztagParamCheck($arrParam, "value"); } } if ($strTransform) { $contentHTML = ztagTransform($contentHTML, $strTransform); } $contentHTML = preg_replace("/\t/", " ", $contentHTML); $contentHTML = ltrim($contentHTML, "\r\n"); $contentHTML = rtrim($contentHTML, "\r\n"); preg_match_all("%^(?P<spaces>[ ]+)?(?P<line>.*?)(\r)?(\n)%sm", $contentHTML . "\r\n", $Matches, PREG_OFFSET_CAPTURE); $contentHTML = ""; $lineMax = 0; $lineMin = 9999; foreach ($Matches[0] as $key => $value) { if (strlen($Matches["line"][$key][0]) > 0 && $lineMax < ($intSize = strlen($Matches["spaces"][$key][0]))) { $lineMax = $intSize; } if (strlen($Matches["line"][$key][0]) > 0 && $lineMin > ($intSize = strlen($Matches["spaces"][$key][0]))) { $lineMin = $intSize; } } foreach ($Matches[0] as $key => $value) { $lineSpaces = $Matches["spaces"][$key][0]; $lineSpaces = substr($lineSpaces, $lineMin, strlen($lineSpaces)); $lineContent = $Matches["line"][$key][0]; if (!$lineAlt) { $lineAlt = " class=\"alt\""; } else { $lineAlt = ""; } $contentHTML .= "<li{$lineAlt}>" . preg_replace("/\\s/", " ", $lineSpaces) . htmlentities($lineContent) . "</li>"; $contentPRE .= $lineSpaces . $lineContent . "\n"; } /* ."<div class=\"bar\">" ."<div class=\"tools\"><a onclick=\"zcodeViewPlain('ViewSource',this);return false;\" href=\"#\">view plain</a>" ."<a onclick=\"zcodeViewSource(this);return false;\" href=\"#\">copy to clipboard</a>" ."<a onclick=\"zcodePrintSource('PrintSource',this);return false;\" href=\"#\">print</a>" ."<a onclick=\"zcodeAbout('About',this);return false;\" href=\"#\">?</a>" ."</div>" ."</div>" */ $html = "<div style=\"border-width: 1px;\">" . "<div style=\"border-bottom-width: 1px;\" class=\"codeHeader panelHeader\"><b>\"{$strTitle}\"</b></div>" . "<div>" . "<div class=\"zcode\">" . "<ol start=\"1\" class=\"dp-c\">" . $contentHTML . "</ol>" . "</div>" . "<pre style=\"display: none;\">" . $contentPRE . "</pre>" . "</div>" . "</div>"; $arrayTag[$tagId][ztagResult] = $html; break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }
/** * Main zTag functions selector * * <code> * zdb_zexecute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zdb_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { global $dbHandleDefault; $arrParam = $arrayTag[$tagId][ztagParam]; $strId = $arrParam["id"]; $strUpdate = $arrParam["update"]; $strDriver = $arrParam["driver"]; $strHost = $arrParam["host"]; $strDatabase = $arrParam["database"]; $strUser = $arrParam["user"]; $strPassword = $arrParam["password"]; $strFilename = $arrParam["filename"]; $strMode = $arrParam["mode"]; $strUse = $arrParam["use"]; $strName = $arrParam["name"]; $strTransform = $arrParam["transform"]; $errorMessage = ""; switch (strtolower($tagFunction)) { /*+ * Open a database connection to defined driver and parameters * * <code> * <zdb:open id="mysqlConn" driver="mysql" host="#mysqlHost" database="#mysqlDatabase" user="******" password="******" charset="utf8"/> * * <zdb:open id="sqliteConn" driver="sqlite" filename="/ZTag/SQLite.db" /> * </code> * * @param string id="MySQL Handle Id" * @param string driver="mssql|mysql|pgsql|sqlite|firebird" * @param string host="Host" * @param string database="Database name" * @param string user="******" * @param string password="******" * @param string charset="utf8" */ case "open": $strCharset = $arrParam["charset"]; $strDriver = constant("db{$strDriver}"); switch ($strDriver) { case dbOCI: $blnDatabase = 0; break; default: $blnDatabase = 1; } if (strlen($strHost)) { ztagReturnConstant($strHost); } if (strlen($strDatabase)) { ztagReturnConstant($strDatabase); } if (strlen($strUser)) { ztagReturnConstant($strUser); } if (strlen($strPassword)) { ztagReturnConstant($strPassword); } switch ($strDriver) { case dbSQLite: if (strlen($strFilename)) { ztagReturnConstant($strFilename); } if (strlen($strMode)) { ztagReturnConstant($strMode); } if (!$strMode) { $strMode = 0666; } $errorMessage .= ztagParamCheck($arrParam, "id,driver,filename"); $dbHandle = dbOpenFile($strDriver, $strFilename, $strMode); if ($arrParam["name"]) { $dbHandleDefault = $dbHandle; } break; case dbFirebird: // @TODO melhorar o esquema de retornar as variáveis, podemos usar o @@ para todas as variáveis, inclusive as constantes $errorMessage .= ztagParamCheck($arrParam, "id,driver,user,password,database"); $dbHandle = dbOpen($strDriver, $strHost, $strDatabase, $strUser, $strPassword); break; case dbMySQL: // @TODO melhorar o esquema de retornar as variáveis, podemos usar o @@ para todas as variáveis, inclusive as constantes if (!$strDatabase && $blnDatabase) { $checkParam .= ",database"; } $errorMessage .= ztagParamCheck($arrParam, "id,driver,host,user,password{$checkParam}"); $dbHandle = dbOpen($strDriver, $strHost, $strDatabase, $strUser, $strPassword, $strCharset); default: // @TODO melhorar o esquema de retornar as variáveis, podemos usar o @@ para todas as variáveis, inclusive as constantes if (!$strDatabase && $blnDatabase) { $checkParam .= ",database"; } $errorMessage .= ztagParamCheck($arrParam, "id,driver,host,user,password{$checkParam}"); $dbHandle = dbOpen($strDriver, $strHost, $strDatabase, $strUser, $strPassword); } if ($errorMessage) { $errorMessage .= "<br />{$strDriver}{$errorMessage}"; } $arrayTagId[$strId][ztagIdHandle] = $dbHandle; $arrayTagId[$strId][ztagIdType] = idTypeDB; $arrayTagId[$strId][ztagIdState] = idStateOpened; break; /*+ * Close the Database connection openned with Id. * * <code> * <zdb:close use="mysqlConn" /> * </code> * * @param string use="mysqlConn" */ /*+ * Close the Database connection openned with Id. * * <code> * <zdb:close use="mysqlConn" /> * </code> * * @param string use="mysqlConn" */ case "close": $errorMessage .= ztagParamCheck($arrParam, "use"); dbClose($arrayTagId[$strUse][ztagIdHandle]); $arrayTagId[$strUse][ztagIdState] = idStateClosed; break; /*+ * Set a SQL query to use with another zDB Tag. * * <code> * <zdb:query use="ociConn" id="ociQuery"> * SELECT US.NM_USUARIO userLogin * , P.NM_PESSOA userName * , P.CD_PESSOA userId * , US.CD_SESSAO_LOGIN userLoginLast * , US.CD_SESSAO_LOGIN_ERRO userLoginError * , US.NU_LOGIN_ERROS userLoginErrors * , to_char(US.DT_LOGIN_BLOQUEIO,'yyyy/mm/dd hh24:mi:ss') userLoginBlocked * FROM TB_USUARIO_SISTEMA US * LEFT JOIN TB_PESSOA P ON US.CD_PESSOA_USUARIO = P.CD_PESSOA * AND FL_ATIVO = 'S' * </zdb:query> * </code> * * @param string use="ociConn" The Id Handle from a Open zDB tag * @param string id="ociQuery" Id where the Query will be saved * @param string update="ociQuery" Id to be updated */ /*+ * Set a SQL query to use with another zDB Tag. * * <code> * <zdb:query use="ociConn" id="ociQuery"> * SELECT US.NM_USUARIO userLogin * , P.NM_PESSOA userName * , P.CD_PESSOA userId * , US.CD_SESSAO_LOGIN userLoginLast * , US.CD_SESSAO_LOGIN_ERRO userLoginError * , US.NU_LOGIN_ERROS userLoginErrors * , to_char(US.DT_LOGIN_BLOQUEIO,'yyyy/mm/dd hh24:mi:ss') userLoginBlocked * FROM TB_USUARIO_SISTEMA US * LEFT JOIN TB_PESSOA P ON US.CD_PESSOA_USUARIO = P.CD_PESSOA * AND FL_ATIVO = 'S' * </zdb:query> * </code> * * @param string use="ociConn" The Id Handle from a Open zDB tag * @param string id="ociQuery" Id where the Query will be saved * @param string update="ociQuery" Id to be updated */ case "query": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = ztagVars($arrayTag[$tagId][ztagContent], $arrayTagId); if (!strlen($strId)) { $errorMessage .= ztagParamCheck($arrParam, "update"); $strId = $strUpdate; } else { $errorMessage .= ztagParamCheck($arrParam, "id"); } if ($strId) { $arrayTagId[$strId][ztagIdValue] = $strContent; $arrayTagId[$strId][ztagIdLength] = strlen($strContent); $arrayTagId[$strId][ztagIdType] = idTypeQuery; $arrayTagId[$strId][ztagIdHandle] = $arrayTagId[$strUse][ztagIdHandle]; } dbQuery($arrayTagId[$strId][ztagIdHandle], $strContent); } else { $errorMessage .= "<br />Tag Query cannot be empty!"; } break; /*+ * Return TRUE if the current record is at the first * * <code> * <zdb:bof use="mysqlConn" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zDB tag */ /*+ * Return TRUE if the current record is at the first * * <code> * <zdb:bof use="mysqlConn" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zDB tag */ case "bof": $errorMessage .= ztagParamCheck($arrParam, "use"); $arrayTag[$tagId][ztagResult] = dbBOF($arrayTagId[$strUse][ztagIdHandle]); break; /*+ * Return TRUE if the current record is at the first * * <code> * <zdb:eof use="mysqlConn" /> * </code> * * use="mysqlConn" - The Id Handle from a Open zDB tag */ /*+ * Return TRUE if the current record is at the first * * <code> * <zdb:eof use="mysqlConn" /> * </code> * * use="mysqlConn" - The Id Handle from a Open zDB tag */ case "eof": $errorMessage .= ztagParamCheck($arrParam, "use"); $arrayTag[$tagId][ztagResult] = dbEOF($arrayTagId[$strUse][ztagIdHandle]); break; /*+ * Return TRUE if the current record is at the first * * <code> * <zdb:field use="mysqlConn" name="NM_NOME" /> * * Or * * <zdb:field name="NM_NOME" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zDB tag */ /*+ * Return TRUE if the current record is at the first * * <code> * <zdb:field use="mysqlConn" name="NM_NOME" /> * * Or * * <zdb:field name="NM_NOME" /> * </code> * * @param string use="mysqlConn" - The Id Handle from a Open zDB tag */ case "field": if ($intFather = $arrayTag[$tagId][ztagFather]) { $arrParam["use"] = "Field_{$intFather}"; } // echo "<br />intFather=$intFather"; $strVar = $arrParam["var"]; $errorMessage .= ztagParamCheck($arrParam, "use,name"); $dbHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandleValue = $dbHandle[dbHandleFetch][$strName]; if ($strTransform) { $dbHandleValue = ztagTransform($dbHandleValue, $strTransform); } if ($strVar) { $arrayTagId["\$" . $strVar][ztagIdValue] = $dbHandleValue; $arrayTagId["\$" . $strVar][ztagIdType] = idTypeField; } $arrayTag[$tagId][ztagResult] = $dbHandleValue; break; /*+ * FieldVar * * <code> * <zdb:fieldvar use="mysqlConn" name="NM_NOME" var="$NM_NOME" /> * </code> * * @param string use="mysqlConn" The Id Handle from a Open zDB tag * @param string name="NM_NOME" * @param string var="$NM_NOME" */ /*+ * FieldVar * * <code> * <zdb:fieldvar use="mysqlConn" name="NM_NOME" var="$NM_NOME" /> * </code> * * @param string use="mysqlConn" The Id Handle from a Open zDB tag * @param string name="NM_NOME" * @param string var="$NM_NOME" */ case "fieldvar": $strVar = $arrParam["var"]; $errorMessage .= ztagParamCheck($arrParam, "use,name,var"); $dbHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandleValue = $dbHandle[dbHandleFetch][$strName]; if ($strTransform) { $dbHandleValue = ztagTransform($dbHandleValue, $strTransform); } if ($strVar) { $arrayTagId["\$" . $strVar][ztagIdValue] = $dbHandleValue; $arrayTagId["\$" . $strVar][ztagIdType] = idTypeField; } break; /*+ * Prepare * * <code> * <zdb:prepare conn="oracleConn" use="oracleQuery" /> * </code> * * @param string conn="oracleConn" * @param string use="oracleQuery" */ /*+ * Prepare * * <code> * <zdb:prepare conn="oracleConn" use="oracleQuery" /> * </code> * * @param string conn="oracleConn" * @param string use="oracleQuery" */ case "prepare": $errorMessage .= ztagParamCheck($arrParam, "use,conn"); $dbHandle = $arrayTagId[$strConn][ztagIdHandle]; $dbQuery = $arrayTagId[$strUse][ztagIdValue]; dbPrepare($dbHandle, $dbQuery); break; /*+ * Prepare * * <code> * <zdb:param use="query002" param="P_CD_PESSOA_USUARIO" var="" type="PARAM_INT" /> * </code> * * @param string use="query002" * @param string param="P_CD_PESSOA_USUARIO" * @param string var="" * @param string type="PARAM_INT" */ /*+ * Prepare * * <code> * <zdb:param use="query002" param="P_CD_PESSOA_USUARIO" var="" type="PARAM_INT" /> * </code> * * @param string use="query002" * @param string param="P_CD_PESSOA_USUARIO" * @param string var="" * @param string type="PARAM_INT" */ case "param": $errorMessage .= ztagParamCheck($arrParam, "id,value"); $arrayTagId[$strId][ztagIdValue] = $strValue; $arrayTagId[$strId][ztagIdLength] = strlen($strValue); $arrayTagId[$strId][ztagIdType] = idTypeFVar; break; /*+ * Create * * <code> * <zdb:create use="query002" /> * </code> * * @param string use="query002" */ /*+ * Create * * <code> * <zdb:create use="query002" /> * </code> * * @param string use="query002" */ case "create": $errorMessage .= ztagParamCheck($arrParam, "id"); if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = $arrayTag[$tagId][ztagContent]; $arrayTagId[$strId][ztagIdValue] = $strContent; $arrayTagId[$strId][ztagIdLength] = strlen($strContent); } break; /*+ * Show * * <code> * <zdb:show use="query002" /> * </code> * * @param string use="query002" */ /*+ * Show * * <code> * <zdb:show use="query002" /> * </code> * * @param string use="query002" */ case "show": $errorMessage .= ztagParamCheck($arrParam, "use"); $arrayTag[$tagId][ztagResult] = $arrayTagId[$strUse][ztagIdValue]; break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }
function zhtml_cellhead($tagId, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strTagId = $arrParam["tagid"]; $strValue = $arrParam["value"]; $strTransform = $arrParam["transform"]; $strContent = $arrayTag[$tagId][ztagContent]; if (strlen($strValue)) { $strContent = $strValue; } $arrParam["value"] = $strContent; if (!$strTagId) { $strTagId = $strName; } $arrParam["id"] = $strTagId; $strTag = "th"; $strParam = ztagParam($arrParam, "alt,align,border,height,width,id,class,style,nowrap,colspan"); $errorMessage = ztagParamCheck($arrParam, "value"); if ($strTransform) { $strContent = ztagTransform($strContent, $strTransform); } $arrayTag[$tagId][ztagResult] = "<{$strTag}{$strParam}>{$strContent}</{$strTag}>"; ztagError($errorMessage, $arrayTag, $tagId); }
/** * Main zTag functions selector * * <code> * znosql_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function znosql_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { $arrParam = $arrayTag[$tagId][ztagParam]; $strId = $arrParam["id"]; $strUse = $arrParam["use"]; $strDatabase = $arrParam["database"]; $strCollection = $arrParam["collection"]; $strName = $arrParam["name"]; $strValue = $arrParam["value"]; $strVar = $arrParam["var"]; $strTransform = $arrParam["transform"]; if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = $arrayTag[$tagId][ztagContent]; } $errorMessage = ""; switch (strtolower($tagFunction)) { /*+ * Open connection to a NoSQL Server * * <code> * <znosql:open id="mongoDB" driver="Mongo" host="username:password@mongodb.zyc.com.br:27017" database="Direito2" collection="pubPaginas" /> * <znosql:open id="mongoDB" driver="Mongo" host="mongodb.zyc.com.br" username="******" password="******" port="27017" database="Direito2" collection="pubPaginas" /> * </code> * * @param string id="mongoDB" * @param string driver="Mongo" * @param string host="username:password@mongodb.zyc.com.br:27017" <-- mongodb://[username:password@]host1[:port1][,host2[:port2:],...] * @param string username="******" * @param string password="******" * @param int port="27017" * @param string options="option=value;option2=value2" * @param string database="Direito2" * @param string collection="pubPaginas" * @param boolean persist="0|1|true|false|x" */ case "open": $strDriver = $arrParam["driver"]; $strHost = $arrParam["host"]; $strUsername = $arrParam["username"]; $strPassword = $arrParam["password"]; $strPort = $arrParam["port"]; $strPersist = $arrParam["persist"]; $strOptions = $arrParam["options"]; ztagReturnConstant($strHost); ztagReturnConstant($strDatabase); ztagReturnConstant($strUsername); ztagReturnConstant($strPassword); ztagReturnConstant($strPort); $errorMessage .= ztagParamCheck($arrParam, "id,driver,host"); $strDriver = constant("nosql{$strDriver}"); if (strlen($strUsername) && strlen($strPassword)) { $strHost = "{$strUsername}:{$strPassword}@{$strHost}"; } if (strlen($strPort)) { $strHost = "{$strHost}:{$strPort}"; } if (strlen($strOptions)) { $strHost = "{$strHost}?{$strOptions}"; } if (extension_loaded('mongo')) { try { $nosqlHandle = array(); if ($strPersist === "true" || $strPersist === "1" || ($strPersist = "x")) { $dbHandle = new Mongo($strHost, array("persist" => "x")); } else { $dbHandle = new Mongo($strHost); } if ($strDatabase) { $nosqlDB = $nosqlHandle->selectDB($strDatabase); } } catch (MongoConnectionException $e) { $errorMessage .= "<br />Cannot connect to {$strDriver} (" . $e->getMessage() . ")"; } if (strlen($strCollection)) { $nosqlColection = $nosqlDB->selectCollection($strCollection); } } else { $errorMessage .= "<br />{$strDriver} extention is not installed!"; } // Set all NoSQL handler structure $nosqlHandle[nosqlHandleDriver] = $strDriver; $nosqlHandle[nosqlHandleHost] = $strHost; $nosqlHandle[nosqlHandleDatabaseName] = $dbDatabase; $nosqlHandle[nosqlHandleUser] = $strUsername; $nosqlHandle[nosqlHandlePassword] = $strPassword; $nosqlHandle[nosqlHandlePort] = $strPort; $nosqlHandle[nosqlHandleId] = $dbHandle; $nosqlHandle[nosqlHandleState] = dbHandleStateOpen; $arrayTagId[$strId][ztagIdHandle] = $nosqlHandle; $arrayTagId[$strId][ztagIdType] = idTypeNoSQL; $arrayTagId[$strId][ztagIdState] = idStateOpened; break; /*+ * Close a Opened NoSQL Handle connection * * <code> * <znosql:close use="mongoDB"> * </code> * * @param string use="mongoDB" * */ /*+ * Close a Opened NoSQL Handle connection * * <code> * <znosql:close use="mongoDB"> * </code> * * @param string use="mongoDB" * */ case "close": if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandle = $nosqlHandle[nosqlHandleId]; $dbHandle->close(); $arrayTagId[$strUse][ztagIdHandle] = $dbHandle; $arrayTagId[$strUse][ztagIdState] = idStateClosed; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Do an Insert in currente Collection * * </code> * <znosql:insert use="mongoDB"> * pagCodigo="1" * , pagNome="Page \"title\"" * , pagResumo='Page \'resume\'' * , pagDescricao:"Page body" * , pagPalavrasChave:{"example","NoSQL"} * , pagInclusao='2010/10/10' * , pagAtivo=1 * </znosql:insert> * * <znosql:insert use="mongoDB" value="$varInsert" /> * </code> * * @param string use="mongoDB" * @param boolean safe="true|false|1|0" * @param boolean fsync="true|false|1|0" */ /*+ * Do an Insert in currente Collection * * </code> * <znosql:insert use="mongoDB"> * pagCodigo="1" * , pagNome="Page \"title\"" * , pagResumo='Page \'resume\'' * , pagDescricao:"Page body" * , pagPalavrasChave:{"example","NoSQL"} * , pagInclusao='2010/10/10' * , pagAtivo=1 * </znosql:insert> * * <znosql:insert use="mongoDB" value="$varInsert" /> * </code> * * @param string use="mongoDB" * @param boolean safe="true|false|1|0" * @param boolean fsync="true|false|1|0" */ case "insert": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleCollection]) { $dbHandle = $nosqlHandle[nosqlHandleId]; $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $strCollection = $nosqlHandle[nosqlHandleCollectionName]; $dbHandleCollection = $nosqlHandle[nosqlHandleCollection]; // Prepare the tag content if (strlen($strContent)) { $contentArray = $strContent; } if (strlen($strValue)) { $contentArray = $strValue; } if (strlen($contentArray)) { $contentArray = ztagVars($contentArray, $arrayTagId); } if (strlen($contentArray)) { $contentArray = ztagRun($contentArray, 0, $arrayTagId); } if (!strlen($strContent) && !strlen($strValue)) { $errorMessage .= ztagParamCheck($arrParam, "value"); } if (strlen($strTransform) && strlen($contentArray)) { $contentArray = ztagTransform($contentArray, $strTransform); } $contentArray = znosql_lib_Content2Array($contentArray); // @TODO Think how to manage the safe option and it's MongoCursorException try { $dbResult = $dbHandleCollection->insert($contentArray); // echo "<br /><pre>".print_r($contentArray, 1)."</pre>"; if (!strlen($dbResult)) { $errorMessage .= "<br />Cannot insert into collection {$strCollection} at database {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>"; } } catch (MongoException $e) { $errorMessage .= "<br />Cannot insert into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Execute a NoSQL commands * * <code> * <znosql:get use="mongoDB"> * Commands * </znosql:get> * </code> * * @param string use="mongoDB" * */ /*+ * Execute a NoSQL commands * * <code> * <znosql:get use="mongoDB"> * Commands * </znosql:get> * </code> * * @param string use="mongoDB" * */ case "getone": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleCollection]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $strCollection = $nosqlHandle[nosqlHandleCollectionName]; $dbHandleCollection = $nosqlHandle[nosqlHandleCollection]; // Prepare the tag content if (strlen($strContent)) { $contentArray = $strContent; } if (strlen($strValue)) { $contentArray = $strValue; } if (strlen($contentArray)) { $contentArray = ztagVars($contentArray, $arrayTagId); } if (!strlen($strContent) && !strlen($strValue)) { $errorMessage .= ztagParamCheck($arrParam, "value"); } if (strlen($strTransform) && strlen($contentArray)) { $contentArray = ztagTransform($contentArray, $strTransform); } $contentArray = ltrim($contentArray, "\r\n"); $contentArray = rtrim($contentArray, "\r\n"); preg_match_all("%criteria\\s*{(?P<criteria>(?:\\}|[^}])*?)}(\\s*,\\s*fields\\s*{(?P<fields>(?:\\}|[^}])*?)})?%", $contentArray, $Matches, PREG_OFFSET_CAPTURE); $arrayCriteria = znosql_lib_Content2Array($Matches["criteria"][0][0]); if ($Matches["fields"][0][0]) { $arrayFields = znosql_lib_Content2Array($Matches["fields"][0][0], 1); } // @TODO Think how to manage the safe option and it's MongoCursorException try { if (count($arrayFields)) { $dbResult = $dbHandleCollection->findOne($arrayCriteria, $arrayFields); } else { $dbResult = $dbHandleCollection->findOne($arrayCriteria); } if (strlen($strVar) && count($dbResult)) { $arrayTagId["\$" . $strVar][ztagIdValue] = $value; $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar; } } catch (MongoConnectionException $e) { $errorMessage .= "<br />Cannot find the criteria into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Execute a NoSQL commands * * <code> * <znosql:get use="mongoDB"> * Commands * </znosql:execute> * </code> * * $query - the evaluation or "where" expression * $orderby - sort order desired * $hint - hint to query optimizer * $explain - if true, return explain plan results instead of query results * $snapshot - if true, "snapshot mode" */ /*+ * Execute a NoSQL commands * * <code> * <znosql:get use="mongoDB"> * Commands * </znosql:execute> * </code> * * $query - the evaluation or "where" expression * $orderby - sort order desired * $hint - hint to query optimizer * $explain - if true, return explain plan results instead of query results * $snapshot - if true, "snapshot mode" */ case "getall": /*$errorMessage .= ztagParamCheck($arrParam, "use"); // $cursor = $this->collection->find($f); $k = array(); $i = 0; while( $cursor->hasNext()) { $k[$i] = $cursor->getNext(); $i++; } // return $k; * */ break; /*+ * Do an Update in currente Collection * * <code> * <znosql:update use="mongoDB"> * criteria{pagCodigo="1"} * , set{pagNome="Page \"title\" Updated" * , pagResumo='Page \'resume\'' * , pagDescricao:"Page body" * , pagPalavrasChave:{"example","NoSQL"} * , pagInclusao='2010/10/10' * , pagAtivo=1 * } * </znosql:update> * * <znosql:update use="mongoDB" criteria="$varCriteria" value="$varInsert" /> * </code> * * @param string use="mongoDB" * @param boolean upsert="true|false|1|0" * @param boolean multiple="true|false|1|0" * @param boolean safe="true|false|1|0" * @param boolean fsync="true|false|1|0" */ /*+ * Do an Update in currente Collection * * <code> * <znosql:update use="mongoDB"> * criteria{pagCodigo="1"} * , set{pagNome="Page \"title\" Updated" * , pagResumo='Page \'resume\'' * , pagDescricao:"Page body" * , pagPalavrasChave:{"example","NoSQL"} * , pagInclusao='2010/10/10' * , pagAtivo=1 * } * </znosql:update> * * <znosql:update use="mongoDB" criteria="$varCriteria" value="$varInsert" /> * </code> * * @param string use="mongoDB" * @param boolean upsert="true|false|1|0" * @param boolean multiple="true|false|1|0" * @param boolean safe="true|false|1|0" * @param boolean fsync="true|false|1|0" */ case "update": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleCollection]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $strCollection = $nosqlHandle[nosqlHandleCollectionName]; $dbHandleCollection = $nosqlHandle[nosqlHandleCollection]; // Prepare the tag content if (strlen($strContent)) { $contentArray = $strContent; } if (strlen($strValue)) { $contentArray = $strValue; } if (strlen($contentArray)) { $contentArray = ztagVars($contentArray, $arrayTagId); } if (!strlen($strContent) && !strlen($strValue)) { $errorMessage .= ztagParamCheck($arrParam, "value"); } if (strlen($strTransform) && strlen($contentArray)) { $contentArray = ztagTransform($contentArray, $strTransform); } $contentArray = ltrim($contentArray, "\r\n"); $contentArray = rtrim($contentArray, "\r\n"); preg_match_all("%criteria\\s*{(?P<criteria>(?:\\}|[^}])*?)}\\s*,\\s*set\\s*{(?P<set>(?:\\}|[^}])*?)}%", $contentArray, $Matches, PREG_OFFSET_CAPTURE); // echo "<br /><pre>".print_r($Matches, 1)."</pre>"; $arrayCriteria = znosql_lib_Content2Array($Matches["criteria"][0][0]); $arraySet = array('$set' => znosql_lib_Content2Array($Matches["set"][0][0])); // @TODO Think how to manage the safe option and it's MongoCursorException try { $dbResult = $dbHandleCollection->update($arrayCriteria, $arraySet); // echo "<br /><pre>".print_r($contentArray, 1)."</pre>"; if (!$dbResult) { $errorMessage .= "<br />Cannot update the criteria into collection {$strCollection} at database {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>"; } } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Cannot update the criteria into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Delete a criteria at current collection * * <code> * <znosql:delete use="mongoDB"> * pagCodigo="1" * </znosql:delete> * * <znosql:delete use="mongoDB" criteria="$varCriteria" /> * </code> * * @param string use="mongoDB" * @param boolean justone="true|false|1|0" * @param boolean safe="true|false|1|0" * @param boolean fsync="true|false|1|0" */ /*+ * Delete a criteria at current collection * * <code> * <znosql:delete use="mongoDB"> * pagCodigo="1" * </znosql:delete> * * <znosql:delete use="mongoDB" criteria="$varCriteria" /> * </code> * * @param string use="mongoDB" * @param boolean justone="true|false|1|0" * @param boolean safe="true|false|1|0" * @param boolean fsync="true|false|1|0" */ case "delete": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleCollection]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $strCollection = $nosqlHandle[nosqlHandleCollectionName]; $dbHandleCollection = $nosqlHandle[nosqlHandleCollection]; // Prepare the tag content if (strlen($strContent)) { $contentArray = $strContent; } if (strlen($strValue)) { $contentArray = $strValue; } if (strlen($contentArray)) { $contentArray = ztagVars($contentArray, $arrayTagId); } if (!strlen($strContent) && !strlen($strValue)) { $errorMessage .= ztagParamCheck($arrParam, "value"); } if (strlen($strTransform) && strlen($contentArray)) { $contentArray = ztagTransform($contentArray, $strTransform); } $contentArray = znosql_lib_Content2Array($contentArray); // echo "<br /><pre>contentArray=".print_r($contentArray, 1)."</pre>"; // @TODO Think how to manage the safe option and it's MongoCursorException try { $dbResult = $dbHandleCollection->remove($contentArray); // echo "<br /><pre>dbResult=".print_r($dbResult, 1)."</pre>"; if (!$dbResult) { $errorMessage .= "<br />Cannot delete the criteria into collection {$strCollection} at database {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>"; } } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Cannot delete the criteria into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Execute a NoSQL commands * * <code> * <znosql:execute use="mongoDB"> * Commands * </znosql:execute> * </code> * * @param string use="mongoDB" * */ /*+ * Execute a NoSQL commands * * <code> * <znosql:execute use="mongoDB"> * Commands * </znosql:execute> * </code> * * @param string use="mongoDB" * */ case "execute": $errorMessage .= ztagParamCheck($arrParam, "use"); // Execute Close, but I don't know yet! $arrayTagId[$strUse][ztagIdState] = idStateClosed; // mongo->execute($cmd); break; /*+ * Set a database for current Opened NoSQL connection * * <code> * <znosql:setdatabase use="mongoDB" name="Direito2" /> * </code> * * @param string use="mongoDB" * @param string name="Direito2" The database name. */ /*+ * Set a database for current Opened NoSQL connection * * <code> * <znosql:setdatabase use="mongoDB" name="Direito2" /> * </code> * * @param string use="mongoDB" * @param string name="Direito2" The database name. */ case "setdatabase": $errorMessage .= ztagParamCheck($arrParam, "use,name"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandle = $nosqlHandle[nosqlHandleId]; try { $dbHandleDatabase = $dbHandle->selectDB($strName); $nosqlHandle[nosqlHandleDatabaseName] = $strName; $nosqlHandle[nosqlHandleDatabase] = $dbHandleDatabase; } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Invalid database name {$strName} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * List all databases * * <code> * <znosql:listdatabases use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize"> * <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" /> * </znosql:listdatabases> * </code> * * @param string use="mongoDB" A NoSQL handle * @param string id="mongoDBlist" Id with array of each line * @param string var="databasesList" Variable with array of each line * @param string total="databasesTotalSize" Variable with total size */ /*+ * List all databases * * <code> * <znosql:listdatabases use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize"> * <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" /> * </znosql:listdatabases> * </code> * * @param string use="mongoDB" A NoSQL handle * @param string id="mongoDBlist" Id with array of each line * @param string var="databasesList" Variable with array of each line * @param string total="databasesTotalSize" Variable with total size */ case "listdatabases": $strTotal = $arrParam["total"]; $errorMessage .= ztagParamCheck($arrParam, "use,id"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandle = $nosqlHandle[nosqlHandleId]; $arrayDatabases = $dbHandle->listDBs(); $totalDbSize = $arrayDatabases['totalSize']; foreach ($arrayDatabases["databases"] as $key => $value) { if (strlen($strId)) { $arrayTagId[$strId][ztagIdValue] = $arrayDatabases["databases"][$key]; $arrayTagId[$strId][ztagIdType] = idTypeValue; } if (strlen($strVar)) { $arrayTagId["\$" . $strVar][ztagIdValue] = $arrayDatabases["databases"][$key]; $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar; } $strResult = ztagRun($strContent, 0, $arrayTagId); $arrayTag[$tagId][ztagResult] .= $strResult; } if (strlen($strTotal)) { $arrayTagId["\$" . $strTotal][ztagIdValue] = $arrayDatabases[totalSize]; $arrayTagId["\$" . $strTotal][ztagIdType] = idTypeFVar; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Return the server Stats * * <code> * <znosql:getstats use="mongoDB" var="mongoStats" /> * </code> * * @param string use="mongoDB" * @param string var="mongoStats" */ /*+ * Return the server Stats * * <code> * <znosql:getstats use="mongoDB" var="mongoStats" /> * </code> * * @param string use="mongoDB" * @param string var="mongoStats" */ case "getstats": if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandle = $nosqlHandle[nosqlHandleId]; $arrayDatabases = $dbHandle->listDBs(); $dbHandleAdmin = $dbHandle->selectDB('admin'); $arrayReturn = array_merge($dbHandleAdmin->command(array('buildinfo' => 1)), $dbHandleAdmin->command(array('serverStatus' => 1))); $profile = $dbHandleAdmin->command(array('profile' => -1)); $arrayReturn['profilingLevel'] = $profile['was']; $arrayReturn['mongoDbTotalSize'] = round($totalDbSize / 1000000) . 'mb'; $prevError = $dbHandleAdmin->command(array('getpreverror' => 1)); if (!$prevError['n']) { $arrayReturn['previousDbErrors'] = 'None'; } else { $arrayReturn['previousDbErrors']['error'] = $prevError['err']; $arrayReturn['previousDbErrors']['numberOfOperationsAgo'] = $prevError['nPrev']; } $arrayReturn['globalLock']['totalTime'] .= ' µSec'; $arrayReturn['uptime'] = round($arrayReturn['uptime'] / 60) . ':' . str_pad($arrayReturn['uptime'] % 60, 2, '0', STR_PAD_LEFT) . ' minutes'; $arrayUnshift['mongo'] = $arrayReturn['version'] . ' (' . $arrayReturn['bits'] . '-bit)'; $arrayUnshift['mongoPhpDriver'] = Mongo::VERSION; $arrayUnshift['phpMoAdmin'] = '1.0.8'; $arrayUnshift['php'] = PHP_VERSION . ' (' . (PHP_INT_MAX > 2200000000.0 ? 64 : 32) . '-bit)'; $arrayUnshift['gitVersion'] = $arrayReturn['gitVersion']; unset($arrayReturn['ok'], $arrayReturn['version'], $arrayReturn['gitVersion'], $arrayReturn['bits']); $arrayReturn = array_merge(array('version' => $arrayUnshift), $arrayReturn); $iniIndex = array(-1 => 'Unlimited', 'Off', 'On'); $phpIni = array('allow_persistent', 'auto_reconnect', 'chunk_size', 'cmd', 'default_host', 'default_port', 'max_connections', 'max_persistent'); foreach ($phpIni as $ini) { $key = 'php_' . $ini; $arrayReturn[$key] = ini_get('mongo.' . $ini); if (isset($iniIndex[$arrayReturn[$key]])) { $arrayReturn[$key] = $iniIndex[$arrayReturn[$key]]; } } if (strlen($strVar)) { $arrayTagId["\$" . $strVar][ztagIdValue] = $arrayReturn; $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Repair the current Database * * <code> * <znosql:repairdatabase use="mongoDB" preserveclonedfiles="true" backuporiginalfiles="true" /> * </code> * * @param boolean preserveclonedfiles="true|false|1|0" * @param boolean backuporiginalfiles="true|false|1|0" */ /*+ * Repair the current Database * * <code> * <znosql:repairdatabase use="mongoDB" preserveclonedfiles="true" backuporiginalfiles="true" /> * </code> * * @param boolean preserveclonedfiles="true|false|1|0" * @param boolean backuporiginalfiles="true|false|1|0" */ case "repairdatabase": $strPreserveClonedFiles = $arrParam["preserveclonedfiles"]; $strBackupOriginalFiles = $arrParam["backuporiginalfiles"]; $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleDatabase]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase]; try { if ($strPreserveClonedFiles === "true" || $strPreserveClonedFiles === "1") { $strPreserveClonedFiles = true; } if ($strBackupOriginalFiles === "true" || $strBackupOriginalFiles === "1") { $strBackupOriginalFiles = true; } if (strlen($strPreserveClonedFiles) && !strlen($strBackupOriginalFiles)) { $dbResult = $dbHandleDatabase->repair($strPreserveClonedFiles); } elseif (strlen($strBackupOriginalFiles)) { $dbResult = $dbHandleDatabase->repair($strPreserveClonedFiles, $strBackupOriginalFiles); } else { $dbResult = $dbHandleDatabase->repair(); } if ($dbResult["ok"] != 1) { $errorMessage .= "<br />Cannot repair the {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>"; } } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Invalid database name {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Drop current database * * <code> * <znosql:dropdatabase use="mongoDB" /> * </code> * * @param string use="mongoDB" */ /*+ * Drop current database * * <code> * <znosql:dropdatabase use="mongoDB" /> * </code> * * @param string use="mongoDB" */ case "dropdatabase": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleDatabase]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase]; try { $dbResult = $dbHandleDatabase->drop(); if ($dbResult["ok"] == 1) { $nosqlHandle[nosqlHandleDatabaseName] = null; $nosqlHandle[nosqlHandleDatabase] = null; } else { $errorMessage .= "<br />Cannot drop the database {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>"; } } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Cannot drop the database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Set a collection for current database * * <code> * <znosql:setcollection use="mongoDB" name="pubPaginas" /> * </code> * * @param string use="mongoDB" * @param string name="pubPaginas" */ /*+ * Set a collection for current database * * <code> * <znosql:setcollection use="mongoDB" name="pubPaginas" /> * </code> * * @param string use="mongoDB" * @param string name="pubPaginas" */ case "setcollection": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleDatabase]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase]; try { $dbHandleCollection = $dbHandleDatabase->selectCollection($strName); $nosqlHandle[nosqlHandleCollectionName] = $strName; $nosqlHandle[nosqlHandleCollection] = $dbHandleCollection; } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Invalid collection name {$strName} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * List all databases * * <code> * <znosql:listcollections use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize"> * <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" /> * </znosql:listcollections> * </code> * * @param string use="mongoDB" A NoSQL handle * @param string id="mongoDBlist" Id with array of each line * @param string var="databasesList" Variable with array of each line * @param string total="databasesTotalSize" Variable with total size */ /*+ * List all databases * * <code> * <znosql:listcollections use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize"> * <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" /> * </znosql:listcollections> * </code> * * @param string use="mongoDB" A NoSQL handle * @param string id="mongoDBlist" Id with array of each line * @param string var="databasesList" Variable with array of each line * @param string total="databasesTotalSize" Variable with total size */ case "listcollections": $strTotal = $arrParam["total"]; $errorMessage .= ztagParamCheck($arrParam, "use,id"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleDatabase]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase]; $arrayCollections = $dbHandleDatabase->listCollections(); foreach ($arrayCollections as $dbHandleCollecion) { if ($strId) { $arrayTagId[$strId][ztagIdValue] = array("name" => $dbHandleCollecion->getName()); $arrayTagId[$strId][ztagIdType] = idTypeValue; } if ($strVar) { $arrayTagId["\$" . $strVar][ztagIdValue] = array("name" => $dbHandleCollecion->getName()); $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar; } $strResult = ztagRun($strContent, 0, $arrayTagId); $arrayTag[$tagId][ztagResult] .= $strResult; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Drop a collection for current database * * <code> * <znosql:dropcollection use="mongoDB" /> * </code> * * @param string use="mongoDB" */ /*+ * Drop a collection for current database * * <code> * <znosql:dropcollection use="mongoDB" /> * </code> * * @param string use="mongoDB" */ case "dropcollection": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleCollection]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $strCollection = $nosqlHandle[nosqlHandleCollectionName]; $dbHandleCollection = $nosqlHandle[nosqlHandleCollection]; try { $dbResult = $dbHandleCollection->drop(); if ($dbResult["ok"] == 1) { $nosqlHandle[nosqlHandleCollectionName] = null; $nosqlHandle[nosqlHandleCollection] = null; } else { $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>"; } } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Create a collection for current database * * </code> * <znosql:createcollection use="mongoDB" name="pubPaginas" /> * </code> * * @param string use="mongoDB" * @param string name="pubPaginas" The name of the collection. * @param boolean capped="true|false|1|0" If the collection should be a fixed size. * @param int size="10000000" If the collection is fixed size, its size in bytes. * @param int max="1000" If the collection is fixed size, the maximum number of elements to store in the collection. */ /*+ * Create a collection for current database * * </code> * <znosql:createcollection use="mongoDB" name="pubPaginas" /> * </code> * * @param string use="mongoDB" * @param string name="pubPaginas" The name of the collection. * @param boolean capped="true|false|1|0" If the collection should be a fixed size. * @param int size="10000000" If the collection is fixed size, its size in bytes. * @param int max="1000" If the collection is fixed size, the maximum number of elements to store in the collection. */ case "createcollection": $errorMessage .= ztagParamCheck($arrParam, "use,name"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleDatabase]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase]; try { $dbHandleCollection = $dbHandleDatabase->createCollection($strName); $nosqlHandle[nosqlHandleCollectionName] = $strName; $nosqlHandle[nosqlHandleCollection] = $dbHandleCollection; } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Cannot create the collection {$strName} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Create a collection for current database * * <code> * <znosql:createcollection use="mongoDB" from="pubPaginas" to="pubPaginasOld"/> * </code> * * @param string use="mongoDB" * @param string from="pubPaginas" * @param string to="pubPaginasOld" */ /*+ * Create a collection for current database * * <code> * <znosql:createcollection use="mongoDB" from="pubPaginas" to="pubPaginasOld"/> * </code> * * @param string use="mongoDB" * @param string from="pubPaginas" * @param string to="pubPaginasOld" */ case "renamecollection": $strFrom = $arrParam["from"]; $strTo = $arrParam["to"]; $errorMessage .= ztagParamCheck($arrParam, "use,name"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; $dbHandle = $nosqlHandle[nosqlHandleId]; if ($nosqlHandle[nosqlHandleDatabase]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $dbResult = $dbHandle->selectDB('admin')->command(array('renameCollection' => "{$strDatabase}.{$strFrom}", 'to' => "{$strDatabase}.{$strTo}")); echo "<pre>" . print_r($dbResult, 1) . "</pre>"; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * List all indexes for a Collection * * <code> * <znosql:listindexes use="mongoDB" collection="pubPaginas" /> * </code> * * @param string use="mongoDB" * @param string collection="pubPaginas" */ /*+ * List all indexes for a Collection * * <code> * <znosql:listindexes use="mongoDB" collection="pubPaginas" /> * </code> * * @param string use="mongoDB" * @param string collection="pubPaginas" */ case "listindexes": return $this->mongo->selectCollection($collection)->getIndexInfo(); break; /*+ * Ensure a index of current collection * * <code> * <znosql:ensureindex use="mongoDB" /> * </code> * * @param string use="mongoDB" */ /*+ * Ensure a index of current collection * * <code> * <znosql:ensureindex use="mongoDB" /> * </code> * * @param string use="mongoDB" */ case "ensureindex": $errorMessage .= ztagParamCheck($arrParam, "use"); if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) { if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) { $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle]; if ($nosqlHandle[nosqlHandleCollection]) { $strDatabase = $nosqlHandle[nosqlHandleDatabaseName]; $strCollection = $nosqlHandle[nosqlHandleCollectionName]; $dbHandleCollection = $nosqlHandle[nosqlHandleCollection]; try { $dbResult = $dbHandleCollection->ensureIndex(); $unique = $unique ? true : false; //signature requires a bool in both Mongo v. 1.0.1 and 1.2.0 // mongo->selectCollection($collection)->ensureIndex($indexes, $unique); if ($dbResult["ok"] == 1) { $nosqlHandle[nosqlHandleCollectionName] = null; $nosqlHandle[nosqlHandleCollection] = null; } else { $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>"; } } catch (InvalidArgumentException $e) { $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")"; } $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle; } else { $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!"; } } else { $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!"; } } else { $errorMessage .= "<br />The {$strUse} type is not a NoSQL!"; } break; /*+ * Delete a index for a Collection * * <code> * <znosql:deleteindex use="mongoDB" collection="pubPaginas" index="pagNome"/> * </code> * * @param string use="mongoDB" * @param string collection="pubPaginas" * @param string index="pagNome" * */ /*+ * Delete a index for a Collection * * <code> * <znosql:deleteindex use="mongoDB" collection="pubPaginas" index="pagNome"/> * </code> * * @param string use="mongoDB" * @param string collection="pubPaginas" * @param string index="pagNome" * */ case "deleteindex": // mongo->selectCollection($collection)->deleteIndex($index); break; /*+ * Return the content of name field of current record * * </code> * <zdb:field use="mongoDBlist" name="name" /> * </code> * * @param string use="mongoDBlist" - The Id Handle from current array * @param string name="name" */ /*+ * Return the content of name field of current record * * </code> * <zdb:field use="mongoDBlist" name="name" /> * </code> * * @param string use="mongoDBlist" - The Id Handle from current array * @param string name="name" */ case "field": $strVar = $arrParam["var"]; $errorMessage .= ztagParamCheck($arrParam, "use,name"); $fieldArray = $arrayTagId[$strUse][ztagIdValue]; $fieldValue = $fieldArray[$strName]; if (strlen($strTransform)) { $fieldValue = ztagTransform($fieldValue, $strTransform); } if (strlen($strVar)) { $arrayTagId["\$" . $strVar][ztagIdValue] = $fieldValue; $arrayTagId["\$" . $strVar][ztagIdType] = idTypeField; } $arrayTag[$tagId][ztagResult] = $fieldValue; break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }
/** * Main zTag functions selector * * <code> * zctrl_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder); * </code> * * @param integer $tagId array id of current zTag of $arrayTag array * @param string $tagFunction name of zTag function * @param array $arrayTag array with all compiled zTags * @param array $arrayTagId array with all Ids values * @param array $arrayOrder array with zTag executing order * * @since 1.0 */ function zctrl_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder) { global $ztagExit; $arrParam = $arrayTag[$tagId][ztagParam]; $strId = $arrParam["id"]; $strUse = $arrParam["use"]; $strValue = $arrParam["value"]; $strKey = $arrParam["key"]; $strTransform = $arrParam["transform"]; $strMessage = $arrParam["message"]; if ($arrayTag[$tagId][ztagContentWidth]) { $strContent = $arrayTag[$tagId][ztagContent]; } $errorMessage = ""; switch (strtolower($tagFunction)) { /*+ * Iterate over arrays executing it's content many time as it's content. * * <code> * <zctrl:foreach use="getAll" value="value"> * <zhtml:b value="$key" />: <zvar:show use="$value" /><br /> * </zctrl:foreach> * * <zctrl:foreach use="getAll" key="key" value="value"> * <zhtml:b value="$key" />: <zvar:show use="$value" /><br /> * </zctrl:foreach> * </code> * * @param string use="getAll" Variable array * @param string key="key" Variable where the array Key with saved * @param string value="value" Variable where the array Value with saved * @param string filename="/Alianca8/File.txt" * @param string filetype="txt" * @param string show="0" */ case "foreach": $strFileName = $arrParam["filename"]; $strFileType = $arrParam["filetype"]; $strShow = strtolower($arrParam["show"]); $errorMessage .= ztagParamCheck($arrParam, "use,value"); if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) { $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!"; } // $strArray = $arrayTagId["$".$strUse][ztagIdValue]; preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE); if (count($Matches[0][0])) { $var = $Matches["var"][0][0]; $index = $Matches["index"][0][0]; $strArray = $arrayTagId["\$" . $var][ztagIdValue]; $strArray = $strArray[$index]; } else { if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) { $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!"; } $strArray = $arrayTagId["\$" . $strUse][ztagIdValue]; } if (is_array($strArray)) { if (strlen($strValue) && !strlen($strKey)) { foreach ($strArray as $value) { $arrayTagId["\$" . $strValue][ztagIdValue] = $value; $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar; $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId); if ($ztagExit) { break; } } } else { foreach ($strArray as $key => $value) { $arrayTagId["\$" . $strKey][ztagIdValue] = $key; $arrayTagId["\$" . $strKey][ztagIdType] = idTypeFVar; $arrayTagId["\$" . $strValue][ztagIdValue] = $value; $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar; $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId); if ($ztagExit) { break; } } } if ($strFileName) { $strFileName = str_replace("\\", "/", $strFileName); if (substr($strFileName, 0, 1) === "/") { $strFileName = substr($strFileName, 1); } $strFileName = SiteRootDir . $strFileName; if (!($handleFile = fopen($strFileName, "w"))) { $errorMessage .= "\r\nCannot open file ({$strFileName})"; } else { if (fwrite($handleFile, $arrayTag[$tagId][ztagResult]) === FALSE) { $errorMessage .= "\r\nCannot write to file ({$strFileName})"; } } fclose($handleFile); } if ($strShow === "false" || $strShow === "0") { $arrayTag[$tagId][ztagResult] = ""; } } break; /*+ * Define a conditional execution of code fragments. * * <code> * <zctrl:if value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" > * </zctrl:if> * * <zctrl:if value="$urlAssunto0" function="empty()|true()|false()|len()"> * </zctrl:if> * * <zctrl:if value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test"> * </zctrl:if> * </code> * * @param string value="value" Variable or value to be used. * @param string operator="e|ne|gt|gte|lt|lte" operator to be used * @param string with="0" second part of an boolean expression * @param string transform="substr(1, 3)" Tranform the value's content * @param string function="empty()|true()|false()|len()" Apply a function to value's content and check if result is true * @param string var="ifVar" Variable to save all if result * @param string show="1|0|true|false" False to not show the If result content */ /*+ * Define a conditional execution of code fragments. * * <code> * <zctrl:if value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" > * </zctrl:if> * * <zctrl:if value="$urlAssunto0" function="empty()|true()|false()|len()"> * </zctrl:if> * * <zctrl:if value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test"> * </zctrl:if> * </code> * * @param string value="value" Variable or value to be used. * @param string operator="e|ne|gt|gte|lt|lte" operator to be used * @param string with="0" second part of an boolean expression * @param string transform="substr(1, 3)" Tranform the value's content * @param string function="empty()|true()|false()|len()" Apply a function to value's content and check if result is true * @param string var="ifVar" Variable to save all if result * @param string show="1|0|true|false" False to not show the If result content */ case "if": $strOperator = $arrParam["operator"]; $strWith = $arrParam["with"]; $strFunction = $arrParam["function"]; $strVar = $arrParam["var"]; $strShow = $arrParam["show"]; if (strlen($strOperator)) { $errorMessage .= ztagParamCheck($arrParam, "value,operator,with"); if (strlen($strTransform)) { $strValue = ztagTransform($strValue, $strTransform); } switch (strtolower($strOperator)) { case "e": $strOperator = "=="; break; case "ne": $strOperator = "<>"; break; case "gt": $strOperator = ">"; break; case "gte|lt|lte": $strOperator = ">="; break; case "lt|lte": $strOperator = "<"; break; case "lte": $strOperator = "<="; break; default: $errorMessage .= "<br />Operator \"{$strOperator}\" does not exist!"; } $strEVal = "if(\$strValue {$strOperator} \$strWith) {return 1;} else {return 0;}"; $strValue = eval($strEVal); } else { if (strlen($strFunction)) { $errorMessage .= ztagParamCheck($arrParam, "value,function"); if (strlen($strTransform)) { $strValue = ztagTransform($strValue, $strTransform); } if (strlen($strFunction)) { $strValue = ztagTransform($strValue, $strFunction); } } else { $errorMessage .= ztagParamCheck($arrParam, "value,function"); } } if ($strValue) { $getValue .= ztagRun($strContent, 0, $arrayTagId); if (($strShow != "false" || $strShow != "0") && strlen($getValue)) { $arrayTag[$tagId][ztagResult] = $getValue; } if (strlen($strVar) && strlen($getValue)) { $arrayTagId["\$" . $strVar][ztagIdValue] = $getValue; $arrayTagId["\$" . $strVar][ztagIdLength] = strlen($getValue); $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar; } } break; /*+ * Output a message and terminate the current script. * * <code> * <zctrl:die message="The script die here!" /> * * <zctrl:die> * The script die here! * </zctrl:die> * </code> * * @param string message="value" Variable or value to be printed */ /*+ * Output a message and terminate the current script. * * <code> * <zctrl:die message="The script die here!" /> * * <zctrl:die> * The script die here! * </zctrl:die> * </code> * * @param string message="value" Variable or value to be printed */ case "die": /*+ * Output a message and terminate the current script. * * <code> * <zctrl:exit message="The script exited here!" /> * * <zctrl:exit> * The script exit here! * </zctrl:exit> * </code> * * @param string message="value" Variable or value to be printed */ /*+ * Output a message and terminate the current script. * * <code> * <zctrl:exit message="The script exited here!" /> * * <zctrl:exit> * The script exit here! * </zctrl:exit> * </code> * * @param string message="value" Variable or value to be printed */ case "exit": $ztagExit = 1; if (strlen($strContent)) { $strMessage = ztagVars($strContent, $arrayTagId); } if (strlen($strMessage)) { $arrayTag[$tagId][ztagResult] = $strMessage; } break; /*+ * Output a string * * <code> * <zctrl:echo message="This an echo message" /> * * <zctrl:echo> * This an echo message * </zctrl:echo> * </code> * * @param string message="value" Variable or value to be used */ /*+ * Output a string * * <code> * <zctrl:echo message="This an echo message" /> * * <zctrl:echo> * This an echo message * </zctrl:echo> * </code> * * @param string message="value" Variable or value to be used */ case "echo": /*+ * Output a string * * <code> * <zctrl:print message="This a print message" /> * * <zctrl:print> * This a print message * </zctrl:print> * </code> * * @param string message="value" Variable or value to be used */ /*+ * Output a string * * <code> * <zctrl:print message="This a print message" /> * * <zctrl:print> * This a print message * </zctrl:print> * </code> * * @param string message="value" Variable or value to be used */ case "print": if (strlen($strContent)) { $strMessage = ztagVars($strContent, $arrayTagId); $arrParam["message"] = $strMessage; } $errorMessage .= ztagParamCheck($arrParam, "message"); if (strlen($strTransform) && strlen($strMessage)) { $strMessage = ztagTransform($strMessage, $strTransform); } if (strlen($strMessage)) { ztagError($strMessage, $arrayTag, $tagId); } break; /*+ * Dumps information about a variable * * <code> * <zctrl:dump message="<b>arrayDump</b>=" use="arrayDump" /> * </code> * * @param string use="arrayDump" Variable to be dumped * @param string message="Message" Message to complement the Dump */ /*+ * Dumps information about a variable * * <code> * <zctrl:dump message="<b>arrayDump</b>=" use="arrayDump" /> * </code> * * @param string use="arrayDump" Variable to be dumped * @param string message="Message" Message to complement the Dump */ case "dump": $errorMessage .= ztagParamCheck($arrParam, "use"); // echo "<hr><pre>".print_r($strUse,1)."</pre>"; // echo "<hr><pre>".print_r($arrayTagId["$".$strUse][ztagIdValue],1)."</pre>"; ztagError($strMessage . var_dump($arrayTagId["\$" . $strUse][ztagIdValue]), $arrayTag, $tagId); break; /*+ * Prints human-readable information about a variable * * <code> * <zctrl:printr message="<b>arrayDump</b>=" use="arrayDump" /> * </code> * * @param string use="arrayDump" Variable to be printed * @param string message="Message" Message to complement the Dump */ /*+ * Prints human-readable information about a variable * * <code> * <zctrl:printr message="<b>arrayDump</b>=" use="arrayDump" /> * </code> * * @param string use="arrayDump" Variable to be printed * @param string message="Message" Message to complement the Dump */ case "printr": ztagError(print_r($arrayTagId, 1), $arrayTag, $tagId); $errorMessage .= ztagParamCheck($arrParam, "use"); ztagError($strMessage . print_r($arrayTagId["\$" . $strUse][ztagIdValue], 1), $arrayTag, $tagId); break; /*+ * Iterate over arrays executing it's content many time as it's content. * * <code> * <zctrl:while value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" > * </zctrl:while> * * <zctrl:while value="$urlAssunto0" function="empty()|true()|false()|len()"> * </zctrl:while> * * <zctrl:while value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test"> * </code> * * @param string use="getAll" Variable array * @param string key="key" Variable where the array Key with saved * @param string value="value" Variable where the array Value with saved */ /*+ * Iterate over arrays executing it's content many time as it's content. * * <code> * <zctrl:while value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" > * </zctrl:while> * * <zctrl:while value="$urlAssunto0" function="empty()|true()|false()|len()"> * </zctrl:while> * * <zctrl:while value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test"> * </code> * * @param string use="getAll" Variable array * @param string key="key" Variable where the array Key with saved * @param string value="value" Variable where the array Value with saved */ case "while": $errorMessage .= ztagParamCheck($arrParam, "use,value"); if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) { $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!"; } $strArray = $arrayTagId["\$" . $strUse][ztagIdValue]; if (is_array($strArray)) { if (strlen($strValue) && !strlen($strKey)) { foreach ($strArray as $value) { $arrayTagId["\$" . $strValue][ztagIdValue] = $value; $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar; $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId); if ($ztagExit) { break; } } } else { foreach ($strArray as $key => $value) { $arrayTagId["\$" . $strKey][ztagIdValue] = $key; $arrayTagId["\$" . $strKey][ztagIdType] = idTypeFVar; $arrayTagId["\$" . $strValue][ztagIdValue] = $value; $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar; $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId); if ($ztagExit) { break; } } } } break; default: $errorMessage .= "<br />Undefined function \"{$tagFunction}\""; } ztagError($errorMessage, $arrayTag, $tagId); }