Example #1
0
 public static function loadFile(&$form, $xmlFileName)
 {
     //get xml as string from xml file
     $xmlString = file_get_contents($xmlFileName);
     //check if file reading was successful
     if (!$xmlString) {
         return Logg('Failure', '', 'Unable to read the file ' . $xmlFileName);
     }
     //load xml
     return self::load($form, $xmlString);
 }
Example #2
0
 public static function getColumns($tableName)
 {
     switch (DB::connection()->getConfig('driver')) {
         case 'pgsql':
             $query = "SELECT column_name, data_type, character_maximum_length, column_default, is_nullable FROM information_schema.columns WHERE table_name = '" . $tableName . "'";
             $columnName = 'column_name';
             $dataType = 'data_type';
             $charMaxLen = 'character_maximum_length';
             $columnDefault = 'column_default';
             $isNullable = 'is_nullable';
             $columnType = 'column_type';
             $reverse = true;
             break;
         case 'mysql':
             $query = "SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMN_DEFAULT, IS_NULLABLE  FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{$tableName}' AND TABLE_SCHEMA='" . DB::connection()->getConfig('database') . "'";
             $columnName = 'COLUMN_NAME';
             $dataType = 'DATA_TYPE';
             $charMaxLen = 'CHARACTER_MAXIMUM_LENGTH';
             $columnDefault = 'COLUMN_DEFAULT';
             $isNullable = 'IS_NULLABLE';
             $columnType = 'COLUMN_TYPE';
             $reverse = false;
             break;
         case 'sqlsrv':
             $parts = explode('.', $tableName);
             $num = count($parts) - 1;
             $table = $parts[$num];
             $query = "SELECT column_name, data_type, character_maximum_length, column_default, is_nullable  FROM " . DB::connection()->getConfig('database') . ".INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'" . $table . "'";
             $columnName = 'column_name';
             $dataType = 'data_type';
             $charMaxLen = 'character_maximum_length';
             $columnDefault = 'column_default';
             $isNullable = 'is_nullable';
             $columnType = 'column_type';
             $reverse = false;
             break;
         default:
             $error = 'Database driver not supported: ' . DB::connection()->getConfig('driver');
             return Logg('Failure', '', $error);
     }
     try {
         $result = DB::select($query);
     } catch (QueryException $e) {
         return Logg('Failure', $e->getCode(), $e->getMessage(), $query);
     }
     $columns = array();
     foreach ($result as $column) {
         $columns[] = ['column_name' => $column->{$columnName}, 'data_type' => $column->{$dataType}, 'max_length' => $column->{$charMaxLen}, 'default' => $column->{$columnDefault}, 'is_nullable' => $column->{$isNullable}, 'column_type' => $column->{$columnType}];
     }
     $log = Logg('Success', '', "Columns found for table {$tableName}");
     $log['columns'] = $columns;
     return $log;
 }
Example #3
0
 function load($from, $exclude = [])
 {
     if (method_exists($this->loader, 'load')) {
         $log = $this->loader->load($this, $from, $exclude);
         if ($log['result'] == 'Failure') {
             $this->isLoaded = false;
             $this->errorString = 'Unable to load form fields';
         }
     } else {
         $log = Logg('Failure', '', 'load() function missing in loader object.');
     }
     return $log;
 }
Example #4
0
 public static function load(&$form, $elementArray)
 {
     if (is_array($elementArray)) {
         foreach ($elementArray as $elem) {
             //only elements with type and name will be loaded
             if (isset($elem['type']) && isset($elem['name'])) {
                 $form->addElement($elem);
             }
         }
     }
     $form->isLoaded = true;
     return Logg('Success', '', 'Elements array is loaded successfully.');
 }
Example #5
0
 public static function loadColumn(&$form, $column)
 {
     $typeMap = ['enum' => 'dropdown', 'set' => 'dropdown', 'int' => 'text', 'tinyint' => 'text', 'smallint' => 'text', 'mediumint' => 'text', 'bigint' => 'text', 'integer' => 'text', 'real' => 'text', 'double' => 'text', 'float' => 'text', 'decimal' => 'text', 'numeric' => 'text', 'datetime' => 'text', 'date' => 'text', 'time' => 'text', 'year' => 'text', 'timestamp' => 'text', 'varchar' => 'text', 'char' => 'text', 'text' => 'textarea', 'tinytext' => 'textarea', 'mediumtext' => 'textarea', 'longtext' => 'textarea', 'blob' => 'textarea', 'tinyblob' => 'textarea', 'mediumblob' => 'textarea', 'longblob' => 'textarea', 'binary' => 'textarea', 'varbinary' => 'textarea', 'point' => 'text', 'multipoint' => 'textarea', 'linestring' => 'textarea', 'multilinestring' => 'textarea', 'polygon' => 'textarea', 'multipolygon' => 'textarea', 'geometry' => 'textarea', 'geometryCollection' => 'textarea'];
     if (!array_key_exists($column['data_type'], $typeMap)) {
         return Logg('Failure', '', 'Column type "' . $column['data_type'] . '" is not supported.');
     }
     $options = [];
     if ($column['data_type'] == 'enum' || $column['data_type'] == 'set') {
         if (preg_match_all('/\'([^\',]+)\'/', $column['column_type'], $matches)) {
             foreach ($matches[1] as $opt) {
                 $options[] = ['value' => $opt, 'label' => $opt];
             }
         }
     }
     $form->addElement(array('type' => $typeMap[$column['data_type']], 'name' => $column['column_name'], 'label' => '', 'mandatory' => 'true', 'options' => $options));
     $form->isLoaded = true;
     return Logg('Success', '', "Column {$column['column_name']} loaded successfully");
 }
Example #6
0
 public function load(&$form, $source, $exclude = null)
 {
     if ($source instanceof SimpleXMLElement) {
         return \X2Form\Loaders\Simplexml::load($form, $source, $exclude);
     } elseif (is_subclass_of($source, 'Illuminate\\Database\\Eloquent\\Model')) {
         //passed laravel Model object or classname
         return \X2Form\Loaders\Eloquent::load($form, $source, $exclude);
     } elseif (is_array($source)) {
         //array passed
         return \X2Form\Loaders\ParamsArray::load($form, $source, $exclude);
     } elseif (is_file($source) && is_readable($source)) {
         //filename passed
         return \X2Form\Loaders\Xml::loadFile($form, $source, $exclude);
     } elseif (is_string($source) && strlen($source) > 50) {
         //xml is passed
         return \X2Form\Loaders\Xml::load($form, $source, $exclude);
     }
     return Logg('Failure', 'The type of source object provided is not supportd.');
 }
Example #7
0
 public function load(&$collection, $source, $exclude = [])
 {
     if ($source instanceof SimpleXMLElement) {
         return $this->loadXmlElement($collection, $source, $exclude);
     } elseif (is_subclass_of($source, 'Illuminate\\Database\\Eloquent\\Model')) {
         //passed laravel Model object or classname
         //we wont find any collection specific data from eloquent model
         //so load the schema directly from the eloquent model
         return \X2Form\Loaders\Eloquent::load($collection->schema, $source, $exclude);
     } elseif (is_array($source)) {
         //params array containing elements is passed
         return \X2Form\Loaders\ParamsArray::load($collection->schema, $source);
     } elseif (is_file($source) && is_readable($source)) {
         //filename passed
         return $this->loadFile($collection, $source, $exclude);
     } elseif (is_string($source) && strlen($source) > 50) {
         //xml is passed
         return $this->loadXML($collection, $source, $exclude);
     }
     return Logg('Failure', 'The type of source object provided is not supported.');
 }
Example #8
0
 public static function load(&$form, $formXmlObj)
 {
     //attributes for the FORM tag, that are to be read from xml, if provided
     $fAttr = array('method' => '', 'action' => '', 'enctype' => '', 'target' => '_self');
     //find form attributes
     foreach ($formXmlObj->attributes() as $k => $v) {
         if (array_key_exists($k, $fAttr)) {
             $fAttr[strtolower("{$k}")] = "{$v}";
         }
     }
     $form->attributes = $fAttr;
     //find the elements in the form
     $elems = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
     foreach ($formXmlObj->elements->children() as $elem) {
         //create X2Form\Element object and store it in array
         $params = self::parseChild($elem);
         if (isset($params['type']) && isset($params['name'])) {
             $form->addElement($params);
         }
     }
     $form->isLoaded = true;
     return Logg('Success', '', 'SimpleXml is loaded successfully.');
 }
Example #9
0
 public function rollBackFileUploads()
 {
     Logg("LOG", '', "Rolling back {$this->name}.<br>");
     $total = count($this->fileSystemChanges);
     if ($total > 0) {
         $upload_dir = $this->config['uploaddirectory'];
         for ($i = $total - 1; $i >= 0; $i--) {
             $change = $this->fileSystemChanges[$i];
             if ($change['action'] == 'upload') {
                 unlink($upload_dir . $change['filename']);
             } elseif ($change['action'] == 'backup' || $change['action'] == 'rename') {
                 rename($upload_dir . $change['toname'], $upload_dir . $change['fromname']);
             }
         }
     }
     $this->value = '';
 }
Example #10
0
 function pdoQuery($queryString, $options, $queryData = null, $dbHandle = null)
 {
     if (!$dbHandle) {
         return Logg("Failure", "10010", "Invalid DB Handle.");
     }
     $stmt = $dbHandle->prepare($queryString);
     if (!stmt) {
         return Logg("Failure", "10011", "Unable to prepare query", $queryString);
     }
     if (!$stmt->execute($queryData)) {
         $error = $stmt->errorInfo();
         return Logg("Failure", "#MYSQL " . $error[0], "MySQL Error..", $stmt->_debugQuery(), $error[2]);
     }
     $log = Logg("Success", "RESULTCODE", "Query executed.", $queryString);
     if (($options & self::GET_COUNT) == self::GET_COUNT) {
         $log['data']['count'] = $stmt->rowCount();
     }
     if (($options & self::FETCH_ONE) == self::FETCH_ONE) {
         $log['data']['records'] = $stmt->fetch(PDO::FETCH_ASSOC);
     }
     if (($options & self::FETCH_ALL) == self::FETCH_ALL) {
         $log['data']['records'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
     }
     if (($options & self::GET_INSERT_ID) == self::GET_INSERT_ID) {
         $log['data']['insert_id'] = $dbHandle->lastInsertId();
     }
     return $log;
 }
Example #11
0
 function processSubmission($postedData, $oldData = array(), $rollbackOnError = true)
 {
     if ($this->validate($postedData, $oldData)) {
         if ($this->hasSteps()) {
             Logg('LOG', 'CODE', 'Submited data for Step:' . $this->activeStep . ' has passed validation.');
             $this->handleFileUploads($postedData, $oldData);
             //mark the step as complete
             $this->steps[$this->activeStep]->isComplete = true;
             //store the data in session
             $_SESSION[$this->name] = $this->getValues();
             //store the stepData as well
             $_SESSION[$this->name . '-step-data'] = $this->getStepData();
             if ($nextStep = $this->getFirstIncompleteStep()) {
                 $this->setStep($nextStep);
                 //update the store the stepData as well
                 $_SESSION[$this->name . '-step-data'] = $this->getStepData();
                 return Logg('Failure', '001', '');
             } else {
                 //there are no remaining steps
                 $this->steps[$this->activeStep]->isActive = false;
                 $this->activeStep = false;
                 unset($_SESSION[$this->name]);
                 unset($_SESSION[$this->name . '-step-data']);
                 return Logg('Success', 'S001', 'Form submission successful.');
             }
         } else {
             Logg('LOG', 'CODE', 'Submited data has passed validation.');
             $this->handleFileUploads($postedData, $oldData);
             return Logg('Success', 'S001', 'Form submission successful.');
         }
     } else {
         if ($rollbackOnError) {
             $this->rollBackFileUploads();
         }
         $log = Logg('Failure', 'E001', 'Problem occured while processing submission.');
         $log['errorFields'] = $this->errorFields;
         return $log;
     }
 }