Esempio n. 1
0
 /**
  * Will make an URL string frmo an associative array. After we took the URL and transformed it into an associative array, we need
  * to make it back to a string that can be used as a LINK to another resoure. This is what this method does.
  *
  * @param A $passedArray The array ot be imploded as as tring
  * @return S The imploded array, returned as a string now
  * @author Elena Ramona <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 09_URL.php 313 2009-10-09 13:27:52Z catalin.zamfir $
  * @since Version 1.0
  * @access private
  * @static
  * @final
  */
 private static final function associativeToURL(A $passedArray)
 {
     $temporaryArray = new A();
     $i = new I(-1);
     foreach ($passedArray as $k => $v) {
         $temporaryArray[$i->doInc()] = $k;
         $temporaryArray[$i->doInc()] = $v;
     }
     // After parsing of the array, return the proper URL new S;
     return new S(implode(_WS, $temporaryArray->toArray()));
 }
Esempio n. 2
0
 /**
  * Will replace module tokens (also named table fields) that can be used independent of the table structure. This provides the
  * basics of our ORM (Object Relationship Mapping) as we can easily separate table fields from the SQL string and have an
  * independent way to query the database freely of the structure or the table/field names;
  *
  * @param S $objSQLParam The SQL string to be processed
  * @return S Will return the current SQL string with modified tokens
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 11_SQL.php 313 2009-10-09 13:27:52Z catalin.zamfir $
  * @since Version 1.0
  * @access protected
  */
 protected function doModuleTokens(A $objTokens, A $objReplac, S $objSQLParam)
 {
     // Modify tokens;
     foreach ($objTokens as $k => $v) {
         // Replace %[theToken] with the corresponding field in the table;
         $objSQLParam->setString(preg_replace('/%\\b' . $v . '\\b/i', $objReplac[$k], $objSQLParam));
     }
     // Do return ...
     return $objSQLParam->doToken($objTokens->toArray(), $objReplac->toArray());
 }
Esempio n. 3
0
 /**
  * Will output a given ajax json array, discarding output, and exiting right after. This method will output and array as a JSON
  * resource to a calling Ajax request;
  *
  * @param A $objArrayToJSON The array to output
  * @return S Outputs the json string, using echo
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 10_TPL.php 315 2009-10-11 07:11:31Z catalin.zamfir $
  * @since Version 1.0
  * @access public
  * @static
  * @final
  */
 public static final function outputAjaxJSON(A $objArrayToJSON)
 {
     // Clean-up around the house ...
     TPL::discardOutputStream(new B(TRUE));
     TPL::switchHTML();
     // Do an echo with JSON;
     echo json_encode($objArrayToJSON->toArray());
     // Unset _SESSION['POST'];
     if (isset($_SESSION['POST'])) {
         unset($_SESSION['POST']);
     }
     // Unset _SESSION['FILES'];
     if (isset($_SESSION['FILES'])) {
         unset($_SESSION['FILES']);
     }
     // DIE ...
     TPL::disableFurtherOutput();
 }
Esempio n. 4
0
 /**
  * Will execute necessary SQL operations on the current form ...
  *
  * This method, setSQLOperationsOnForm, you don't need to know the internal workings of it. This is because, as you can see
  * it is a private method, and thus, it's used internally by the class, to achieve it's goals of execution. Just pass on
  * and read any other 'public' or 'protected' method out there ...
  *
  * @return object The current object instance;
  */
 private static function setSQLOperationsOnForm()
 {
     if (isset(self::$objFormDataContainer['table_name'])) {
         if (isset(self::$objFormDataContainer['table_name']) && isset(self::$objUpdateWhere)) {
             $q = new S('SELECT * FROM %table WHERE %condition LIMIT 1');
             $q->doToken('%table', self::$objFormDataContainer['table_name']);
             $q->doToken('%condition', self::$objUpdateWhere);
             if (self::getQuery($q)->doCount()->toInt() == 0) {
                 self::$objFormDataContainer['update_or_insert'] = new S('insert');
             }
         }
         // Do update;
         if (isset(self::$objFormDataContainer['update_or_insert']) && self::$objFormDataContainer['update_or_insert'] == new S('update')) {
             // Check to see if update_id is set. We can't update on something that doesn't exist!
             if (isset(self::$objUpdateWhere)) {
                 // For each _SESSION['POST'] key, do an update ...
                 foreach ($_SESSION['POST'] as $k => $v) {
                     if (in_array($k, self::$objUpdateTableFields->toArray())) {
                         $q = new S('UPDATE %table SET %who = "%what" WHERE %condition');
                         $q->doToken('%table', self::$objUpdateTableName)->doToken('%who', $k)->doToken('%what', $v)->doToken('%condition', self::$objUpdateWhere);
                         self::getQuery($q);
                     }
                 }
                 // Do additional SQLs ...
                 foreach (self::$objOtherSQLData as $k => $v) {
                     $q = new S('UPDATE %table SET %who = "%what" WHERE %condition');
                     $q->doToken('%table', self::$objUpdateTableName)->doToken('%who', $k)->doToken('%what', $v)->doToken('%condition', self::$objUpdateWhere);
                     self::getQuery($q);
                 }
             }
         } else {
             if (isset(self::$objFormDataContainer['update_or_insert']) && self::$objFormDataContainer['update_or_insert'] == new S('insert')) {
                 if (isset(self::$objFormDataContainer['table_save_into'])) {
                     $insertTableArray = self::$objFormDataContainer['table_save_into'];
                     $insertTable = self::$objFormDataContainer['table_save_into']->toValues();
                     $insertTableCount = count($insertTable);
                     for ($i = 0; $i < $insertTableCount; ++$i) {
                         foreach ($_SESSION['POST'] as $k => $v) {
                             if (isset($insertTableArray[$k]) && isset($insertTable[$i]) && $insertTableArray[$k] == $insertTable[$i]) {
                                 $detectedMULTIPLEInputs[$insertTable[$i]][] = $k;
                             }
                         }
                     }
                     foreach ($detectedMULTIPLEInputs as $k => $v) {
                         $a = new A();
                         $q = new S('INSERT INTO %table SET' . _SP);
                         $q->doToken('%table', $k);
                         $detectedMULTIPLEInputs[$k] = array_unique($v);
                         $tableFields = self::getFieldsFromTable(new S($k));
                         foreach ($_SESSION['POST'] as $kv => $vv) {
                             $r = new S('%who = "%what"');
                             if (in_array($kv, $tableFields->toArray())) {
                                 $a[] = $r->doToken('%who', $kv)->doToken('%what', $vv);
                             }
                         }
                         foreach (self::$objOtherSQLData as $k => $v) {
                             $r = new S('%who = "%what"');
                             if (in_array($k, $tableFields->toArray())) {
                                 $a[] = $r->doToken('%who', $k)->doToken('%what', $v);
                             }
                         }
                         $q->appendString(implode(', ', $a->toArray()));
                         self::getQuery($q);
                     }
                     // Do for the native table ...
                     if (isset(self::$objFormDataContainer['table_name'])) {
                         $a = new A();
                         $q = new S('INSERT INTO %table SET' . _SP);
                         $q->doToken('%table', self::$objFormDataContainer['table_name']);
                         $tableFields = self::getFieldsFromTable(self::$objFormDataContainer['table_name']);
                         foreach ($_SESSION['POST'] as $k => $v) {
                             if (in_array($k, $tableFields->toArray())) {
                                 $r = new S('%who = "%what"');
                                 $a[] = $r->doToken('%who', $k)->doToken('%what', $v);
                             }
                         }
                         foreach (self::$objOtherSQLData as $k => $v) {
                             $r = new S('%who = "%what"');
                             if (in_array($k, $tableFields->toArray())) {
                                 $a[] = $r->doToken('%who', $k)->doToken('%what', $v);
                             }
                         }
                         $q->appendString(implode(', ', $a->toArray()));
                         self::getQuery($q);
                     }
                 } else {
                     $a = new A();
                     $q = new S('INSERT INTO %table SET' . _SP);
                     $q->doToken('%table', self::$objFormDataContainer['table_name']);
                     $tableFields = self::getFieldsFromTable(self::$objFormDataContainer['table_name']);
                     foreach ($_SESSION['POST'] as $k => $v) {
                         $r = new S('%who = "%what"');
                         if (in_array($k, $tableFields->toArray())) {
                             $a[] = $r->doToken('%who', $k)->doToken('%what', $v);
                         }
                     }
                     foreach (self::$objOtherSQLData as $k => $v) {
                         $r = new S('%who = "%what"');
                         if (in_array($k, $tableFields->toArray())) {
                             $a[] = $r->doToken('%who', $k)->doToken('%what', $v);
                         }
                     }
                     // Just do it;
                     $q->appendString(implode(', ', $a->toArray()));
                     self::getQuery($q);
                 }
             }
         }
     }
 }