/cruddy_mysql/cruddy_mysql.php
PHP | 4400 lines | 4166 code | 141 blank | 93 comment | 408 complexity | 14e8a6c0cc2f839665545141e25f6d3d MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- $pwd = dirname(__FILE__);
- define("ABS_PATH_TO_CRUDDY_MYSQL_FOLDER",dirname($_SERVER['PHP_SELF']).'/cruddy_mysql/');
- define("ABS_PATH_HASH",substr(md5(dirname($_SERVER['PHP_SELF']).'/cruddy_mysql/'),0,8));
- ini_set("memory_limit","256M");
- set_time_limit(0);
- set_magic_quotes_runtime(false); // -- dude just dont use magic quotes...
- function get_microtime_ms() {
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
- /* constants */
- define("GET_COLUMNS_SQL", "show full columns from %s");
- define("GET_TABLES_SQL", "show full tables");
- define("GET_DATABASES_SQL", "show databases");
- define("UPDATE_SQL","update %s set %s where %s");
- define("INSERT_SQL","insert into %s(%s) values(%s)");
- define("TABLE_CONFIG","tableDef");
- define("CRUD_FIELD_CONFIG","crudConfig");
- // table level keys and configs
- define("OBJECT_DESC","description"); //high level table description (Keep short)
- define("OBJECT_ACTIONS","actions"); //array of possible CRUD actions used in switch of controller page
- define("OBJECT_DEFAULT_ORDER","defaultorder"); //for a generic_read function to handle how the records should be initially sorted
- define("OBJECT_READ_FILTER","filterrecords"); //initial filter that the main recordset loads as
- define("OBJECT_HIDE_NEW_LINK","hidenewlink"); //a flag to say whether the table should have a "New" link associated with it
- define("OBJECT_HIDE_VIEW_LINK","hideviewlink"); //a flag to say whether the table should have a "New" link associated with it
- define("OBJECT_HIDE_SEARCH_LINK","hidesearchlink");
- define("OBJECT_HIDE_DETAILS_LINK","hidedetailslink");
- define("OBJECT_HIDE_EDIT_LINK","hideeditlink");
- define("OBJECT_HIDE_DELETE_LINK","hidedeletelink");
- define("OBJECT_DELETE_CHECK_CONSTRAINTS","objdeleteconstraints"); //by default the crud class will loop through all tables and fields and if it finds an identical fieldname in any table in the database and there are records in that table, it will tell the user they cannot delete the only way to bypass this constraint is by setting this to false
- define("OBJECT_TABLE","table");//table name
- define("OBJECT_IS_AGGREGATE","aggregateview");//table name
- define("OBJECT_CONNECTION_STRING","connection");//dba connection string
- define("OBJECT_PK","primarykey");//primary key hard coded
- define("OBJECT_FILTER_DESC","filterrecordsdescription");//used when you want to describe what the data is filtered by inside your controller function
- define("OBJECT_PAGING","pagingenabled");//by default paging is enabled unless you say false here. paging is defaulted to 10 records per page but just need to add new configuration here when needing new functionality
- define("OBJECT_PAGING_NUM_ROWS_PER_PAGE","pagingrows");
- define("OBJECT_PAGING_SCROLL","pagingscroll");
- define("OTHER_OBJECTS", "otherobjects" );//otherobjects allows you to build supporting form objects that will be tacked on at the end of the form before the button to post/update
- define("REQUIRED_TEXT","requiredtext");
- define("OTHER_LINKS", "otherlinks" );
- define("EDIT_TEXT","edittext");
- define("DELETE_TEXT","deletetext");
- define("TABLE_TEXT","tabletext");
- define("ADD_TEXT","addtext");
- define("VIEW_TEXT","viewtext");
- define("SEARCH_TEXT","searchtext");
- define("EDIT_LINK", "editlink");
- define("DELETE_LINK", "deletelink");
- // field level keys and configs
- define("CAPTION","caption"); // what the user sees as the field name
- //these array keys/configurations are for the foreign key lookups definied at the field level
- define("ID","lookupid");
- define("TEXT", "lookuptext");
- define("TABLE", "lookuptable" );
- define("WHERE", "lookupwhere" );
- define("SELECT","select");
- define("SHOWCOLUMN","showcolumn");
- define("COLUMNPOSTTEXT","posttextc");
- define("SORTABLE","sortable");
- define("PRETEXTREAD","pretext");
- define("POSTTEXTREAD","posttext");
- define("REQUIRED","required");
- define("UPDATE_READ_ONLY","ronlyupdate");
- define("HIDE","inserthide");
- define("ROW_ID","number_0x45dsa4654das654da64dsa654da");
- define("INPUT_DOIT","submit_cruddy_mysql");
- define("INPUT_SUBMIT","submit_button");
- (include ("$pwd/dbal/dbal.php")) or die("This class require <a href='http://cesars.users.phpclasses.org/dba'>DBA</a> class. Please download it and copy the folder 'dbal' in $pwd");
- (include ("$pwd/forms.php")) or die("This class require <a href='http://cesars.users.phpclasses.org/formsgeneration'>Forms Generation Class</a> class. Please download it and copy the file 'forms.php' in $pwd");
- class cruddyMysql {
- function cruddyMysql($str,$table,$info=array()) {
- $pwd = dirname(__FILE__);
- $this->table = $info[TABLE_CONFIG][OBJECT_TABLE];
- $this->conn = $str;
- $this->dba = new dbal($str);
- $this->dba->setCacheDir( "${pwd}/cache/" );
- $this->tableDefinition = $info;
- $this->getTableInformation();
- }
- function doQuery($filter) {
- $methodStartTime = get_microtime_ms();
- $res = &$this->result;
- $dba = &$this->dba;
- $info = &$this->formParams;
- $definitions = &$this->tableDefinition;
- if (!empty($filter)) {
- if ( ( stristr($filter,'=') || stristr($filter,'IN (') || stristr($filter,'IN(') ) && !stristr($filter,'where') ) {
- $f = $filter == '' ? '' : ' WHERE '.$filter;
- } else {
- $f = $filter;
- }
- } else {
- $f = $filter;
- }
- $query = "select count(*) as count from ".$this->table." $f";
- $result = @mysql_query($query,$dba->dbm->dbh);
- if ($result) {
- $row = mysql_fetch_array($result);
- $total_records = $row['count'];
- } else {
- $total_records = 0;
- }
- $scroll_page = ($definitions[TABLE_CONFIG][OBJECT_PAGING_NUM_ROWS_PER_PAGE]) ? $definitions[TABLE_CONFIG][OBJECT_PAGING_SCROLL] : 5 ;
- $per_page = ($definitions[TABLE_CONFIG][OBJECT_PAGING_NUM_ROWS_PER_PAGE]) ? $definitions[TABLE_CONFIG][OBJECT_PAGING_NUM_ROWS_PER_PAGE] : 10 ;
- $current_page = $_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['page']];
- $pager_url = $_SERVER['PHP_SELF']."?action=".strtolower($definitions[TABLE_CONFIG][OBJECT_ACTIONS]['read'].$this->object_key).'&'.$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_field'].'='.$_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_field']].'&'.$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_direction'].'='.$_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_direction']].'&'.$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['page'].'=';
- $inactive_page_tag = 'id="current_page"';
- $previous_page_text = '< Previous';
- $next_page_text = 'Next >';
- $first_page_text = '<< First';
- $last_page_text = 'Last >>';
- $crudPage = new cruddyMysqlPager();
- $crudPage->pager_set($pager_url, $total_records, $scroll_page, $per_page, $current_page, $inactive_page_tag, $previous_page_text, $next_page_text, $first_page_text, $last_page_text,'');
- $result = mysql_query(str_replace("count(*) as count","*",$query)." LIMIT ".$crudPage->start.", ".$crudPage->per_page."",$dba->dbm->dbh);
- $definitions[TABLE_CONFIG][OBJECT_PAGING] = $crudPage;
- if ($result) {
- while ($row = mysql_fetch_assoc($result)) {
- $res[] = $row;
- }
- } else {
- //if ($this->cruddyAdministrator) {
- echo ("ERROR: ".$dba->getLastError());
- //}
- }
- $total = (get_microtime_ms() - $methodStartTime);
- $this->performance['doQuery'][] = $total ." sql:".$query;
- }
- /**
- * Creates a new row.
- *
- * Show the form for create a new row.
- */
- function create() {
- $this->getTableInformation(true);
- return $this->buildGenericForm(array(),false,"");
- }
- /**
- * search
- */
- function search() {
- $this->getTableInformation("search");
- return $this->buildGenericForm(array(),false,"",false,true);
- }
- /**
- * Generic Form
- *
- * @access private
- */
- function buildGenericForm($default=array(),$update=false,$update_condition="",$readOnly=false,$search=false) {
- $methodStartTime = get_microtime_ms();
- $form = new form_class;
- $form->NAME= $this->table."_form";
- $form->METHOD="POST";
- $form->ACTION="";
- $form->ENCTYPE="multipart/form-data";
- $form->InvalidCLASS="invalid";
- $form->ResubmitConfirmMessage="Are you sure you want to submit this form again?";
- $form->OptionsSeparator="<br />\n";
- $form->ErrorMessagePrefix="- ";
- $form->ErrorMessageSuffix="";
- foreach($this->formParams as $k => $input) {
- if ( is_array($default) && count($default) > 0) {
- $input["VALUE"] = $default[$k];
- }
- if ($input["NAME"]) {
- echo $form->AddInput( $input );
- }
- }
- $form->LoadInputValues($form->WasSubmitted(INPUT_DOIT));
- $verify=array();
- $doit=false;
- $error_message="";
- if($form->WasSubmitted(INPUT_DOIT)) {
- if(($error_message=$form->Validate($verify))!="") {
- $doit=false;
- } else {
- $doit=true;
- }
- }
- if($doit) {
- $dba = &$this->dba;
- // -- get a list of fields that the table can take skip anything else in the post
- $sql = sprintf(GET_COLUMNS_SQL,$this->table);
- $record = $dba->query($sql);
- if ( !$record )
- return false;
- $Field = & $record->bindColumn('Field');
- while ( $foo=$record->getNext() ) {
- $tableFields[$Field] = $Field;
- }
- $sql = "";
- $columns=array();
- foreach($this->formParams as $k=>$v) {
- if ( $k == ROW_ID || $k == INPUT_DOIT || $k == INPUT_SUBMIT) continue;
- if (!in_array($k,$tableFields)) {
- // -- found another form element see if there is something to do with it
- continue;
- } else {
- if (strtoupper($v['TYPE']) == 'FILE') {
- $form->GetFileValues($k,$userfile_values);
- if ($userfile_values["name"]) {
- // -- for files, user should be mapping the MIME, MOVE_TO, and SIZE to other fields
- $columns[$k] = $k;
- $values[$k] = $k;
- $_POST[$k] = $userfile_values["name"];
- // -- users can store the MIME and FILE_SIZE attributes into a custom field mapping
- // -- FYI there is no edit facility for MIME/SIZE you must convert your config to an array and manually add them to the $field_name_"config" section of the array
- // -- MIME is meant to update another field with the MIME type of the fileupload and expects a field name as the value of the key
- if ($v['MIME']) {
- $columns[$v['MIME']] = $v['MIME'];
- $values[$v['MIME']] = $v['MIME'];
- $_POST[$v['MIME']] = $userfile_values["type"];
- }
- if ($v['FILE_SIZE']) {
- $columns[$v['FILE_SIZE']] = $v['FILE_SIZE'];
- $values[$v['FILE_SIZE']] = $v['FILE_SIZE'];
- $_POST[$v['FILE_SIZE']] = $userfile_values["size"];
- }
- if (isset($v['MOVE_TO'])) {
- if (@is_uploaded_file($userfile_values["tmp_name"])) {
- if (substr($v['MOVE_TO'],-1))
- if (substr($v['MOVE_TO'],-1) != '/' && strtoupper(substr(PHP_OS,0,3)!='WIN')) {
- $v['MOVE_TO'] .= "/";
- } elseif (substr($v['MOVE_TO'],-1) != "\\" && strtoupper(substr(PHP_OS,0,3)=='WIN')) {
- $v['MOVE_TO'] .= "\\";
- }
- if (!@move_uploaded_file($userfile_values["tmp_name"], $v['MOVE_TO'].$userfile_values["name"])) {
- die("File Upload Failed. Ensure that {$v['MOVE_TO']} is chmod 777 for new files to overwrite.");
- }
- }
- } else {
- die("Missing MOVE_TO value to move the file");
- }
- } else {
- }
- } elseif (strtoupper($v['CustomClass']) == 'FORM_DATE_CLASS') {
- $dateValue = $_POST["p_".$k."_year"]."-".$_POST["p_".$k."_month"]."-".$_POST["p_".$k."_day"];
- if (empty($_POST["p_".$k."_year"]) || empty($_POST["p_".$k."_month"])) {
- $dateValue = "";
- }
- $_POST[$k] = $dateValue;
- $values[$k] = $k;
- $columns[$k] = $k;
- } else {
- if ($v["UsesAutoFormName"] ==! false) {
- // -- custom flag for use when widget calls $forms->GenerateInputID()
- $columns[$k] = $k;
- $values[$k] = "p_".$k."_".$v["UsesAutoFormName"];
- } else {
- $columns[$k] = $k;
- $values[$k] = $k;
- }
- }
- }
- }
- if ( $update ) {
- $updatx = array();
- foreach($columns as $k=>$v) {
- if (isset($_POST[$k])) {
- $updatx[] = " $v = :$values[$k]";
- }
- }
- $sql = sprintf(UPDATE_SQL, $this->table,implode(" , ",$updatx),$update_condition);
- } else {
- foreach($columns as $k=>$v) {
- if (intval(substr($k,0,1)) > 0) {
- // -- column starts with a number - unsupported
- unset($columns[$k],$values[$k]);
- }
- if (!isset($_POST[$k])) {
- unset($columns[$k],$values[$k]);
- }
- }
- $sql = sprintf(INSERT_SQL, $this->table,implode(", ",$columns),":".implode(", :",$values));
- }
- $dba->compile($sql);
- // -- support multi-value inserts/updates
- $multi=false;
- foreach ($_POST as $postKey=>$postValue) {
- if (is_array($postValue)) {
- $cnt++;
- $multi=true;
- $multiArray = $postValue;
- $multiArrayKey = $postKey;
- }
- }
- if ($cnt != 1 && $multi === true) {
- $error_message="You can only have 1 multi select for each row.";
- return false;
- }
- if ($multi === false ) {
- $f = $dba->execute($_POST);
- } else {
- foreach ($multiArray as $insertValue) {
- $_POST[$multiArrayKey] = $insertValue;
- $f = $dba->execute($_POST);
- }
- }
- if ( $f ) {
- if ($update) {
- return true;
- } else {
- $lastInsert = mysql_insert_id($this->dba->dbm->dbh);
- $_POST[$this->tableDefinition[TABLE_CONFIG][OBJECT_PK]] = $lastInsert;
- return $lastInsert;
- }
- } else {
- $str = $dba->getLastError();
- if ( substr(strtolower($str),0,9) == "duplicate") {
- $error_message="Duplicated data";
- $s = strpos($str,"'")+1;
- $e = strpos($str,"'",$s);
- $err = trim( substr($str,$s,$e-$s) );
- foreach($columns as $k => $v) {
- if ( $err == $_POST[$v]) {
- $verify[$v] = $v;
- }
- }
- } else {
- $error_message="There was a database error that occurred in saving this record.";
- if ($this->cruddyAdministrator) {
- $error_message = $str;
- echo $dba->__sql;
- }
- }
- }
- }
- $total = (get_microtime_ms() - $methodStartTime);
- $this->performance['buildGenericForm'][] = $total;
- $this->autoTemplate($form,$error_message,$verify,$update,$readOnly,$search);
- return false;
- }
- function update($arr) {
- if ( !is_array($arr) ) return false;
- $filter=Array();
- foreach($arr as $k=>$v) {
- $filter[] ="$k = \"".addslashes($v)."\"";
- }
- $this->doQuery(implode(" && ",$filter));
- return$this->buildGenericForm($this->result[0], true, implode(" && ",$filter) );
- }
- function view($arr) {
- if ( !is_array($arr) ) return false;
- $filter=Array();
- foreach($arr as $k=>$v) {
- $filter[] ="$k = \"".addslashes($v)."\"";
- }
- $this->doQuery(implode(" && ",$filter));
- return$this->buildGenericForm($this->result[0], true, implode(" && ",$filter),true);
- }
- function delete($arr) {
- if ( !is_array($arr) ) return false;
- $filter=Array();
- foreach($arr as $k=>$v) {
- $filter[] ="$k = \"".addslashes($v)."\"";
- }
- $filter = implode(" && ",$filter);
- $dba = &$this->dba;
- $definitions = &$this->tableDefinition;
- $f = $filter == '' ? 'XXXXXXXXX Unsupported XXXXXXXXX' : ' where '.$filter;
- $r = $dba->query(GET_TABLES_SQL);
- if (empty($r)) {
- $parts = explode("/",$this->conn);
- $database = $parts[sizeof($parts)-1];
- $r = $dba->query(GET_TABLES_SQL." from $database");
- if (empty($r)) {
- $r = $dba->query("SHOW TABLES FROM $database");
- if (empty($r)) {
- die("<div class=\"error\">Could not get table listing from $database</div>");
- }
- }
- }
- if ( $r ) {
- $Table = & $r->bindColumn('Tables_in_'.$dba->info['db']);
- $Type = & $r->bindColumn('Table_type');
- $dependentRecords = false;
- while ( $foo=$r->getNext() ) {
- if (strtolower($Table) == strtolower($definitions[TABLE_CONFIG][OBJECT_TABLE])) {
- // -- dont check current table
- continue;
- }
- $record2 = $dba->query(sprintf(GET_COLUMNS_SQL,$Table));
- if ( $record2 ) {
- $Field2 = & $record2->bindColumn('Field');
- while ( $foo2=$record2->getNext() ) {
- if ($definitions[TABLE_CONFIG][OBJECT_PK] == $Field2) {
- // -- rules are if you have a table with the same field name and you didnt specify to OBJECT__CHECK_CONSTRAINTS => false
- if ($definitions[TABLE_CONFIG][OBJECT_DELETE_CHECK_CONSTRAINTS] == 1) {
- if ($Type == 'BASE TABLE') {
- foreach($arr as $k=>$v) {
- if ($k == $Field2) {
- $valueWhere = $v;
- break;
- }
- }
- $record3 = $dba->query("SELECT * FROM ".$Table." WHERE ".$Field2." = '".$valueWhere."'");
- if ( $record3->_result != null ) {
- if ($_GET['confirm']==1 && $_GET['table']==$Table) {
- $dba->query("DELETE FROM ".$Table." WHERE ".$Field2." = '".$valueWhere."'");
- header("Location: ".rawurldecode($_GET['redir']));
- } else {
- $dependentRecords = "There are dependent records in \"".$Table."\" and you cannot delete this ".$Field2.". Would you like to delete these dependent records too? <a href='".$_SERVER['REQUEST_URI']."&table=$Table&confirm=1&redir=".rawurlencode($_SERVER['REQUEST_URI'])."'>Yes</a>";
- }
- }
- }
- }
- }
- }
- }
- }
- if ($dependentRecords==false) {
- $r = $dba->execute("delete from ".$this->table." $f");
- } else {
- $r = false;
- echo $dependentRecords;
- }
- }
- return $r != false;
- }
- function buildSearchWhere($currentTable='') {
- $definitions = &$this->tableDefinition;
- if ($currentTable!='') {
- $definitions = $this->currentAdminDB[CRUD_FIELD_CONFIG][$currentTable];
- }
- foreach($_COOKIE as $k=>$v) {
- if (stristr($k,$definitions[TABLE_CONFIG]['alias']."~")) {
- $column = str_replace($definitions[TABLE_CONFIG]['alias']."~","",$k);
- if (!empty($v) && $v != "null") {
- if (isset($definitions[$column])) {
- // -- valid column config with a search cookie value
- $where .= " AND `$column` like '%".mysql_real_escape_string($v)."%' ";
- // if ($definitions[$column][TABLE]) {
- // $res = mysql_query("select ".$definitions[$column][TEXT]." from ".$definitions[$column][TABLE]." WHERE `$column` = '".mysql_real_escape_string($v)."'");
- // var_dump(mysql_fetch_assoc($res));
- // }
- $desc .= "<div style='-moz-border-radius:8px 8px 8px 8px;border: 3px ridge #485254; float: left;cursor:pointer;' onclick='if (window.confirm(\"Do you want to remove the `".$definitions[$column][CAPTION]."` filter?\")) { eraseCookie(\"$k\"); document.location = document.location; } '><span style='font-size: 19px;color:#7F7F7F;'>".$definitions[$column][CAPTION]."</span>→<span style='font-size: 19px;color:#7F7F7F;'>\"".$v."\"</span></div><div style='float:left;margin-top:7px;'> + </div>";
- }
- if (!isset($definitions[$column]) && $currentTable!='') {
- $desc = '';
- $where = '';
- }
- }
- }
- }
- $desc = substr($desc,0,-49);
- return array($where,$desc);
- }
- /**
- * READ
- * @param string $filter SQL filter.
- */
- function read($filter='') {
- $methodStartTime = get_microtime_ms();
- $definitions = &$this->tableDefinition;
- list($wh,$desc) = $this->buildSearchWhere();
- if (!stristr($filter,"order")) {
- $filter .= $wh;
- } elseif ($wh) {
- $filter = str_replace("1=1","1=1 $wh", $filter);
- }
- if (!empty($definitions[TABLE_CONFIG][OBJECT_DEFAULT_ORDER]) && !stristr($filter,"order")) {
- $filter .= " ORDER BY `".$definitions[TABLE_CONFIG][OBJECT_DEFAULT_ORDER]."`";
- }
-
- $this->doQuery($filter);
- $res = &$this->result;
- $info = &$this->formParams;
- echo "<table>\n";
- if ( is_array($res) ) {
-
- echo "<thead>
- <tr>";
-
- if ($definitions[TABLE_CONFIG][OBJECT_IS_AGGREGATE]) {
- echo "<th>Database</th>";
- }
- foreach($definitions as $key => $value) {
- if ( !is_array($value) || $value[SHOWCOLUMN] == 0 || !isset($value[SHOWCOLUMN])) continue;
- // -- if the field doesnt say to NOT sort
- if ( ($definitions[TABLE_CONFIG][SORTABLE] == 1 || !isset($definitions[TABLE_CONFIG][SORTABLE])) && !$definitions[TABLE_CONFIG][OBJECT_IS_AGGREGATE]) {
- if ($_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_direction']] == 'ASC') {
- $direction = 'DESC';
- $directionAscii = '↓';
- } else {
- $direction = 'ASC';
- $directionAscii = '↑';
- }
- // -- only set direction arrow if on current field
- if (strtoupper($_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_field']]) == strtoupper($key)) {
- if ($_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_direction']] == 'ASC') {
- $directionAscii = '↑';
- } else {
- $directionAscii = '↓';
- }
- } else {
- $directionAscii = '';
- }
- if (!empty($_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['page']])) {
- $direction .= '&'.$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['page'].'='.$_GET[$definitions[OBJECT_ACTIONS]['page']];
- }
- $sortLinkStart = "<a href='?action=".strtolower($definitions[TABLE_CONFIG][OBJECT_ACTIONS]['read'].$this->object_key).'&'.$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_field'].'='.$key.'&'.$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['order_direction'].'='.$direction;
- if ($this->isPageInclude) {
- $sortLinkStart .= "&conf=$this->current_config";
- }
- $sortLinkStart .= "'>$directionAscii";
- $sortLinkEnd = "</a>";
- }
- echo " <th>".$sortLinkStart.$value[CAPTION].$sortLinkEnd."</th>\n";
- $sortLinkStart = $sortLinkEnd = '';
- }
- echo "</tr>
- </thead>";
-
- //
- $databases = array();
- if ($definitions[TABLE_CONFIG][OBJECT_IS_AGGREGATE]) {
- foreach ($definitions[TABLE_CONFIG]['all_databases'] as $server=>$values) {
- foreach ($values as $database) {
- $databases[$database]['db_name'] = $database;
- //$databases[$database]['db_port'] = $definitions[TABLE_CONFIG]['all_ports'][$server];
- $databases[$database]['db_password'] = $definitions[TABLE_CONFIG]['all_passwords'][$server];
- $databases[$database]['db_server'] = $definitions[TABLE_CONFIG]['all_servers'][$server];
- $databases[$database]['db_user'] = $definitions[TABLE_CONFIG]['all_users'][$server];
- }
- }
- } else {
- $database = $this->dba->info['db'];
- $databases[$database]['db_name'] = $database;
- $databases[$database]['db_port'] = $this->dba->info['user'];
- $databases[$database]['db_password'] = $this->dba->info['pass'];
- $databases[$database]['db_server'] = $this->dba->info['host'];
- $databases[$database]['db_user'] = $this->dba->info['user'];
- }
-
- $aggregateTotals = array();
- foreach ($databases as $dbId=>$dbAttribs) {
- $this->dba->setHost($dbAttribs['db_server']);
- $this->dba->setPass($dbAttribs['db_password']);
- $this->dba->setUser($dbAttribs['db_user']);
- $this->dba->connectToNewDB($dbAttribs['db_name']);
- $res = array();
- $this->doQuery($filter);
- $res = &$this->result;
-
- foreach($res as $k => $r) {
- $pagedResults = (array)$r;
- echo " <tr>\n";
- if ($definitions[TABLE_CONFIG][OBJECT_IS_AGGREGATE]) {
- echo "<td>{$dbAttribs['db_name']}</td>";
- }
- $edit_url = $definitions[TABLE_CONFIG][EDIT_LINK];
- $del_url = $definitions[TABLE_CONFIG][DELETE_LINK];
- if ($definitions[TABLE_CONFIG][OBJECT_HIDE_EDIT_LINK] == 1) {
- $edit_url = "";
- }
- if ($definitions[TABLE_CONFIG][OBJECT_HIDE_DELETE_LINK] == 1) {
- $del_url = "";
- }
- foreach($pagedResults as $k2 => $v2) {
- $edit_url = str_replace('%'.$k2.'%', $v2, $edit_url);
- $del_url = str_replace('%'.$k2.'%', $v2, $del_url);
- }
- $count=0;
- foreach($definitions as $k => $v) {
- if (!is_array($v)) {continue;}
- if ( ! isset($v[SHOWCOLUMN]) || $v[SHOWCOLUMN] == 0) continue;
- $count++;
- $text = "";
- if (isset($v[PRETEXTREAD])) {
- $processedText = $v[PRETEXTREAD];
- foreach($pagedResults as $k2 => $v2) {
- $processedText = str_replace('%'.$k2.'%', $v2, rawurldecode($processedText));
- }
- $text .= $processedText;
- }
- $dataElementValue = (isset($info[$k]["OPTIONS"][$r[$k]]) && !empty($r[$k])) ? $info[$k]["OPTIONS"][$r[$k]] : $r[$k];
- if (is_numeric($dataElementValue)) {
- $aggregateTotals[$k] += $dataElementValue;
- } /*else {
- $aggregateTotals[$k] = 'N/A';
- }*/
- $text .= htmlentities($dataElementValue);
- if (isset($v[POSTTEXTREAD])) {
- $processedText = $v[POSTTEXTREAD];
- foreach($pagedResults as $k2 => $v2) {
- $processedText = str_replace('%'.$k2.'%', $v2, rawurldecode($processedText));
- }
- $text .= $processedText;
- }
- if (empty($text) && $text !=='0') {
- $text .= "<span style='color:#EBEBEB'>(No ".$v[CAPTION].")</span>";
- }
- $linkStart = $linkEnd = "";
- if ($definitions[TABLE_CONFIG][OBJECT_HIDE_DETAILS_LINK] == 0 && $count == 1) {
- $linkStart = "<a href='".str_replace("update_","view_",$edit_url);
- if ($this->isPageInclude) {
- $linkStart .= "&conf=$this->current_config";
- }
- $linkStart .= "'>";
- $linkEnd = "</a>";
- }
- if (strlen($text) > 30 && preg_match("|<[^>]+>(.*)</[^>]+>|U",$text)==0 && !stristr($text,"<img") && !stristr($text,"<input")) {
- $text = substr($text,0,30)."...";
- }
- if ($info[$k]["TYPE"] == 'select') {
- $parts = parse_url($definitions[TABLE_CONFIG]['connection']);
- if (!$this->isPageInclude) {
- $text .= " <strong style=\"color:black;\">(<a href=\"?action=view_".str_replace("/","",$parts['path'])."_".$v[TABLE]."&". $v[ID] . "=". $r[$k] ."\">{$r[$k]}</a>)</strong>";
- }
- }
- echo "<td>".$linkStart.stripslashes($text).$linkEnd."</td>\n";
- // -- debug the row
- //echo "<td>".var_export($r,true)."</td>";
- }
- if (!empty($edit_url)) {
- $edTxt = ($definitions[TABLE_CONFIG][EDIT_TEXT]) ? $definitions[TABLE_CONFIG][EDIT_TEXT] : 'Edit';
- $edit = '<a title="Edit this '.$definitions[TABLE_CONFIG][OBJECT_DESC].'" href="'.$edit_url;
- if ($this->isPageInclude) {
- $linkStart .= "&conf=$this->current_config";
- }
- $edit .= '">'.$edTxt.'</a> - ';
- }
- if (!empty($del_url)) {
- $delTxt = ($definitions[TABLE_CONFIG][DELETE_TEXT]) ? $definitions[TABLE_CONFIG][DELETE_TEXT] : "Delete";
- $delete = '<a title="Delete this '.$definitions[TABLE_CONFIG][OBJECT_DESC].'" href="javascript:if(window.confirm(\'Are you sure you wish to delete this '.$this->object_name.'?\')){document.location=\''.$del_url.'\';}">'.$delTxt.'</a>';
- }
- if (is_array($definitions[TABLE_CONFIG][OTHER_LINKS])) {
- $other = '';
- foreach ($definitions[TABLE_CONFIG][OTHER_LINKS] as $key=>$value) {
- $other_url = $value;
- foreach($r as $k2 => $v2) {
- $other_url = str_replace('%'.$k2.'%', $v2, rawurldecode($other_url));
- }
- $other .= ' - <a href="'.$other_url.'">'.$key.'</a>';
- }
- }
- echo '<td><nobr>'.$edit.$delete.$other.'</nobr></td>'."\n";
- echo "</tr>\n";
- }
- }
-
- if ($definitions[TABLE_CONFIG][OBJECT_IS_AGGREGATE]) {
- echo "<tr>";
- echo "<td>Totals</td>";
- foreach ($aggregateTotals as $kAgg=>$vAgg) {
- echo "<td>$vAgg</td>";
- }
- echo "</tr>\n\n";
- }
-
- } else {
- echo "<tr> \n";
- if ($_COOKIE['current_db']) {
- list($void,$db) = explode('-',$_COOKIE['current_db']);
- $db .= " ";
- }
- echo "<td><h2>No ".$db.$definitions[TABLE_CONFIG][OBJECT_DESC]."'s found.</h2></td>";
- echo "</tr> \n";
- }
- echo '</table>';
- echo '<p id="paging_links">';
- if ($definitions[TABLE_CONFIG][OBJECT_PAGING] -> next_page != "" || !empty($_GET[$definitions[TABLE_CONFIG][OBJECT_ACTIONS]['page']])) {
- echo $definitions[TABLE_CONFIG][OBJECT_PAGING] -> first_page;
- echo $definitions[TABLE_CONFIG][OBJECT_PAGING] -> previous_page;
- echo $definitions[TABLE_CONFIG][OBJECT_PAGING] -> page_links;
- echo $definitions[TABLE_CONFIG][OBJECT_PAGING] -> next_page;
- echo $definitions[TABLE_CONFIG][OBJECT_PAGING] -> last_page;
- }
- $this->performance['readGeneric'][] = (get_microtime_ms() - $methodStartTime);
- echo '</p>';
- }
- /**
- * Generate a basic template for the form.
- *
- * @param object $form Form object
- * @access private
- */
- function autoTemplate($form,$error_message,$verify,$update,$readOnly=false,$search=false) {
- $methodStartTime = get_microtime_ms();
- $def = &$this->tableDefinition;
- $formParams = &$this->formParams;
- $formParams[INPUT_SUBMIT] = $this->button;
- $form->StartLayoutCapture();
- if (!empty($error_message)) {
- echo '<div class="error">'.$error_message.'</div>';
- }
- // -- logic to hide/show based on cookies (also show a post text to unset the search cookie)
- if ($search == true) {
- $disp = "style=\"display:none;\" id=\"{$def[TABLE_CONFIG]['alias']}_search\"";
- }
- echo '<table '.$disp.' summary="Input fields table">';
- if ($search == true) {
- $jsSearch = array();
- foreach($this->formParams as $inpName => $i) {
- $form->inputs[$inpName]['VALUE'] = '';
- $p = '';
- if (substr($inpName,2) == 'p_') {
- $p = 'p_';
- }
- $newSearchId = $p.$inpName."_search";
- $form->inputs[$inpName]['NAME'] = $newSearchId;
- $form->inputs[$inpName]['ID'] = $newSearchId;
- $form->inputs[$newSearchId] = $form->inputs[$inpName];
- unset($form->inputs[$inpName]);
- $possibleSearchKey = $def[TABLE_CONFIG]['alias']."~".$inpName;
- $possibleSearchVal = $_COOKIE[$possibleSearchKey];
- if ($possibleSearchVal) {
- $form->inputs[$newSearchId]['VALUE'] = $possibleSearchVal;
- }
- $jsAll .= "if ($('$newSearchId')) { createCookie('$possibleSearchKey',$('$newSearchId').value,500);} ";
- $jsSearch[$inpName.'_search'] = "$('$newSearchId').value='';eraseCookie('$possibleSearchKey');";
- }
- }
-
- foreach($this->formParams as $inpName => $i) {
- $continue = true;
-
- if ($search == true) {
- $originalInputName = $inpName;
- $inpName = $inpName . "_search";
- }
- if (is_array($def[TABLE_CONFIG][OTHER_OBJECTS])) {
- foreach ($def[TABLE_CONFIG][OTHER_OBJECTS] as $key=>$value) {
- if ($key == $inpName) {
- $continue = false;
- }
- }
- }
- if ( $inpName == INPUT_DOIT || $inpName == INPUT_SUBMIT) {
- $continue = false;
- }
- if (!isset($i['NAME'])) {
- $continue = false;
- }
- if ($continue === true) {
- if ( isset($def[$inpName][HIDE]) && $def[$inpName][HIDE] ) {
- echo "<tr style=\"display:none;\">\n";
- } else {
- echo "<tr>\n";
- }
- echo "<th align=\"right\">";
- if ($search) {
- echo "<label for=\"$inpName\">".$def[$originalInputName][CAPTION]."</label>";
- echo " (<a style=\"cursor:pointer;\" onclick=\"{$jsSearch[$inpName]}\">X</a>)";
- } else {
- echo $form->AddLabelPart(array("FOR"=>$inpName));
- }
- echo "</th>\n";
- echo "<td>";
- if ( isset($def[$inpName][UPDATE_READ_ONLY]) && $def[$inpName][UPDATE_READ_ONLY] || $readOnly === true) {
- $form->AddInputReadOnlyPart( $inpName );
- } else {
- $form->AddInputPart($inpName);
- }
- if ($search) {
- echo " <a style=\"cursor:pointer;\" onclick=\"$('{$def[TABLE_CONFIG]['alias']}_bttn').onclick();\">⇒</a>";
- }
- echo $def[$inpName][COLUMNPOSTTEXT]."</td>\n";
- echo "<td>". (IsSet($verify[$inpName]) ? "[Verify]" : "")."</td>\n";
- echo "</tr>\n";
- }
- }
- if ( isset($def[TABLE_CONFIG][OTHER_OBJECTS]) && is_array($def[TABLE_CONFIG][OTHER_OBJECTS])) {
- // -- for now additional elements draw right before the input box
- foreach ($def[TABLE_CONFIG][OTHER_OBJECTS] as $key=>$value) {
- echo "<tr>";
- if (strtoupper($value['TYPE']) != 'HIDDEN') {
- echo '<th align="right">';
- echo $this->formParams[$key]['LABEL'];
- echo ':</th>';
- }
- echo "\n<td>";
- $form->AddInputPart($key);
- echo "</td>\n";
- echo "<td></td>\n";
- echo "</tr>\n";
- }
- }
- if ($readOnly === false && $search == false) {
- echo '<tr><th align="right"></th>';
- echo "\n";
- echo '<td>';
- echo '<input name="'.INPUT_DOIT.'" value="1" TYPE="hidden"/><input name="'.INPUT_SUBMIT.'" value="'.$this->formParams[INPUT_SUBMIT]["VALUE"].'" onclick="if(this.disabled || typeof(this.disabled)==\'boolean\') this.disabled=true ; form_submitted_test=form_submitted ; form_submitted=true ; form_submitted=(!form_submitted_test || confirm(\''.$form->ResubmitConfirmMessage.'\')) ; if(this.disabled || typeof(this.disabled)==\'boolean\') this.disabled=false ; sub_form=\'\' ; return true" id="'.INPUT_SUBMIT.'" type="submit">';
- echo "</td>\n";
- echo "<td></td>\n";
- echo "</tr>\n";
- } elseif ($search == true) {
- foreach ($jsSearch as $k=>$v) {
- $tmp .= $v;
- }
- echo '<tr><th><input value="Clear All" onclick="'.$tmp.'" type="button"></th>';
- echo '<td>';
- echo '<input value="Search" id="'.$def[TABLE_CONFIG]['alias'].'_bttn" onclick="'.$jsAll.'document.location = location.pathname + \'?action=show_'.$def[TABLE_CONFIG]['alias'].'\';" type="button">';
- echo "</td>";
- echo "<td></td>";
- echo "</tr>";
- }
-
- echo '</table>';
- $form->EndLayoutCapture();
- $form->DisplayOutput();
- $total = (get_microtime_ms() - $methodStartTime);
- $this->performance['autoTemplate'][] = $total;
- }
- /**
- * Get information about the table
- *
- * @access private.
- */
- function getTableInformation($insert=false) {
- $methodStartTime = get_microtime_ms();
- $dba = &$this->dba;
- $info = &$this->tableDefinition;
- unset($this->formParams);
- $formParams = &$this->formParams;
- $sql = sprintf(GET_COLUMNS_SQL,$this->table);
- $record = $dba->query($sql);
- if ( !$record )
- return false;
- $Field = & $record->bindColumn('Field');
- $Type = & $record->bindColumn('Type');
- $Null = & $record->bindColumn('Null');
- $Key = & $record->bindColumn('Key');
- $Extra = & $record->bindColumn('Extra');
- $Default = & $record->bindColumn('Default');
- $Comment = & $record->bindColumn('Comment');
- while ( $foo=$record->getNext() ) {
- $actInfo = & $info[$Field];
- if (stristr($Comment,"lookup")) {
- list($type,$table,$field,$value) = explode(",",$Comment);
- $actInfo[TABLE] = trim($table);
- $actInfo[ID] = trim($field);
- $actInfo[TEXT] = trim($value);
- }
- $actInfoFormOverRides = & $info[$Field."_config"];
- /* reseting form information */
- $form = array();
- if ($Extra == 'auto_increment') {
- continue;
- }
- /**
- * If the field is autoincrement, we
- * do not need to show it on the form.
- */
- $display = "";
- if ( isset($actInfo[HIDE]) && $actInfo[HIDE] ) {
- $form["READONLY"] = "true";
- }
- $this->comments[$Field] = $Comment;
- $this->datatypes[$Field] = $Type;
- $autoType = $this->parseColumnInfo($Type,$foo['Default'],$Field);
- $form["NAME"] = trim($Field);
- $form["ID"] = $form["NAME"];
- // -- if table is configured as not null then user has to enter something
- /*if (strtoupper($Null) == 'NO') {
- $form["ValidateAsNotEmpty"] = 1;
- }*/
- // -- if developer tells class that the field is non-required then set dont set as required
- if($actInfo[REQUIRED] == 1 && isset($actInfo[REQUIRED])) {
- $form["ValidateAsNotEmpty"] = 1;
- $form["Optional"] = false;
- $form["LABEL"] .="<span class='required'>".$info[TABLE_CONFIG][REQUIRED_TEXT]."</span>";
- } else {
- $form["Optional"] = true;
- unset($form["ValidateAsNotEmpty"]);
- }
- $form["LABEL"] = isset($actInfo[CAPTION]) ? $actInfo[CAPTION] : $Field;
- if (isset($actInfo[TABLE]) && isset($actInfo[ID]) && isset($actInfo[TEXT])) {
- $form["TYPE"] = "select";
- $opt = & $form["OPTIONS"];
- if (isset($actInfo[WHERE])) {
- $where = " where ".$actInfo[WHERE]." order by `".$actInfo[TEXT]."` ASC";
- }
- if (substr($actInfo[ID],0,23) == '___distinct___lookup___' || substr($actInfo[TEXT],0,23) == '___distinct___lookup___') {
- $distinct = "distinct";
- $actInfo[ID] = substr($actInfo[ID],23);
- $actInfo[TEXT] = substr($actInfo[TEXT],23);
- }
- $rec1 = $dba->query("select ".$distinct." ".$actInfo[ID].",".$actInfo[TEXT]." from ".$actInfo[TABLE].$where);
- if ( !$rec1 ) {
- continue;
- }
- //@ToDo - say couldnt join if admin
- $opt[""] = "Select a : ".$form["LABEL"];
- while ( $f = $rec1->getNext() ) {
- if ( !isset($form["VALUE"]) ) $form["VALUE"]= "";
- if (strlen($f[ $actInfo[TEXT] ]) > 300 ) {
- $val = substr($f[ $actInfo[TEXT] ],0,300)."...";
- } else {
- $val = $f[ $actInfo[TEXT] ];
- }
- $this->cachedLookup[$hash]["ID"] = $f[$actInfo[ID] ];
- $this->cachedLookup[$hash]["VALUE"] = $val;
- $opt[ $f[$actInfo[ID] ] ] = $val;
- }
- if ($actInfoFormOverRides['TYPE'] != 'select_multi') {
- unset($actInfoFormOverRides['TYPE']);
- }
- } else if ( isset($actInfo[SELECT]) ){
- $form["TYPE"] = "select";
- $form["OPTIONS"] = array_merge(array(""=>"Select: ".$form["LABEL"]),$actInfo[SELECT]);
- $form["VALUE"] = array_shift( array_keys($actInfo[SELECT]) );
- } else {
- $form["TYPE"] = $autoType["TYPE"];
- }
- $form["ValidationErrorMessage"] = "'".$form["LABEL"]."' is required.";
- if (is_array($autoType)) {
- foreach ($autoType as $autoTypeKey=>$autoTypeVal) {
- if (!isset($form[$autoTypeKey])) {
- $form[$autoTypeKey] = $autoType[$autoTypeKey];
- }
- }
- }
- if ( $type["TYPE"]=="select" ) {
- $form["VALUE"] = strlen($Default)>0? $Default : current($form["OPTIONS"]);
- }
- /**
- * Override Field Configuration based on field_config array
- */
- if (!empty($actInfoFormOverRides)) {
- foreach ($actInfoFormOverRides as $option=>$optionValue) {
- $form[$option] = $optionValue;
- }
- }
- if (isset($form['ValidateAsURL'])) {
- unset($form['ValidateAsURL']);
- $form["ReplacePatterns"] = array(
- "^[ \t\r\n]+"=>"",
- "[ \t\r\n]+\$"=>"",
- "^([wW]{3}\\.)"=>"http://\\1",
- "^([^:]+)\$"=>"http://\\1",
- "^(http|https)://(([-!#\$%&'*+.0-9=?A-Z^_`a-z{|}~]+\.)+[A-Za-z]{2,6}(:[0-9]+)?)\$"=>"\\1://\\2/"
- );
- $form["ValidateRegularExpression"] = '^(http|https)\://(([-!#\$%&\'*+.0-9=?A-Z^_`a-z{|}~]+\.)+[A-Za-z]{2,6})(\:[0-9]+)?(/)?/';
- $form["ValidationErrorMessage"] = (!isset($form["ValidateAsURLErrorMessage"])) ? "This is not a valid URL" : $form["ValidateAsURLErrorMessage"];;
- }
- if ($actInfoFormOverRides['TYPE'] == 'select_multi') {
- $form["TYPE"] = "select";
- $form["SIZE"] = "8";
- $form["NAME"] = $Field."[]";
- $form["ValidateOnlyOnClientSide"] = true;
- $form["ExtraAttributes"] = array("multiple"=>"multiple");
- }
- if ($form['TYPE'] == 'wysiwyg' || $actInfoFormOverRides['TYPE'] == 'wysiwyg') {
- unset($form['TYPE']);
- require_once("form_FCKEditor.php");
- $form["TYPE"] = "custom";
- $form["CustomClass"] = "form_FCKEditor";
- $form["BasePath"] = ABS_PATH_TO_CRUDDY_MYSQL_FOLDER."fck/";
- $form["HEIGHT"] = 400;
- $form["WIDTH"] = 800;
- $form["Skin"] = "silver";
- $form["UsesAutoFormName"] = "instance";
- }
- if ($form['TYPE'] == 'date' || $form['TYPE'] == 'timestamp') {
- $form["TYPE"] = "custom";
- $form["CustomClass"] = "form_date_class";
- if ($insert=='search') {
- $form["VALUE"] = '';
- $form["ChooseControl"] = 0;
- } else {
- $form["VALUE"] = 'now';
- $form["ChooseControl"] = 1;
- }
- $form["Format"] = "{day}/{month}/{year}";
- $form["Months"] = array(
- ""=>"Select A Month",
- "01"=>"January",
- "02"=>"February",
- "03"=>"March",
- "04"=>"April",
- "05"=>"May",
- "06"=>"June",
- "07"=>"July",
- "08"=>"August",
- "09"=>"September",
- "10"=>"October",
- "11"=>"November",
- "12"=>"December"
- );
- }
- if (!isset($form["STYLE"]) && $form['TYPE'] == 'textarea') {
- $form["STYLE"] = "WIDTH:500px;HEIGHT:250px;";
- }
- if ($form['TYPE'] == 'select' && $actInfoFormOverRides['TYPE'] != 'select_multi' && isset($form['SIZE'])) {
- unset($form['SIZE']);
- }
- $formParams[$Field] = $form;
- }
- if ( isset($info[TABLE_CONFIG][OTHER_OBJECTS]) && is_array($info[TABLE_CONFIG][OTHER_OBJECTS]) ) {
- // -- for now additional elements draw right before the input box
- foreach ($info[TABLE_CONFIG][OTHER_OBJECTS] as $key=>$value) {
- $formParams[$key] = $value;
- }
- }
- $this->performance['getTableInfo'][] = (get_microtime_ms() - $methodStartTime);
- }
- /**
- * Analyze the column type, parse it, and return
- * to the class for prepare the form.
- *
- * @access private
- * @param string $type MySQL column description
- * @return array Parsed information
- */
- function parseColumnInfo($type,$Default,$Field) {
- $type = trim($type);
- $pos = strpos($type,'(');
- if ( $pos !== false) {
- $extra = substr($type,$pos+1);
- $extra[strlen($extra)-1] = ' ';
- $type = substr($type,0,$pos);
- }
- $return = array();
- if (!empty($Default)) {
- $return["VALUE"] = $Default;
- }
- switch( strtolower($type) ) {
- case "int":
- $return["TYPE"] = "text";
- $return["MAXLENGTH"] = $extra;
- $return["SIZE"] = (floor($extra/1.5) > 50) ? 50 : floor($extra/1.5);
- if ($Field == $this->tableDefinition[TABLE_CONFIG][OBJECT_PK]) {
- $return["ValidateAsInteger"] = 1;
- }
- break;
- case "float":
- $t=explode(",",$extra);
- $return["TYPE"] = "text";
- $return["MAXLENGTH"] = $t[0]+$t[1]+1;
- $return["SIZE"] = (floor($t[0]+$t[1]+1/1.5) > 50) ? 50 : floor($t[0]+$t[1]+1/1.5);;
- if ($Field == $this->tableDefinition[TABLE_CONFIG][OBJECT_PK]) {
- $return["ValidateAsFloat"] = 1;
- }
- break;
- case "varchar":
- $return["TYPE"] = "text";
- $return["MAXLENGTH"] = $extra;
- $return["SIZE"] = (floor($extra/1.5) > 50) ? 50 : floor($extra/1.5);
- if ($Field == $this->tableDefinition[TABLE_CONFIG][OBJECT_PK]) {
- $return["ValidateAsNotEmpty"] = 1;
- }
- break;
- case "mediumtext":
- case "longtext":
- $return["TYPE"] = "textarea";
- $return["STYLE"] = "WIDTH:500px;HEIGHT:250px;";
- $return["MAXLENGTH"] = ($type == 'mediumtext') ? 16777215 : 4294967296;
- break;
- case "date":
- require_once("form_date.php");
- $return["TYPE"] = "custom";
- $return["CustomClass"] = "form_date_class";
- $return["VALUE"] = 'now';
- $return["ChooseControl"] = 1;
- $return["Format"] = "{day}/{month}/{year}";
- $return["Months"] = array(
- ""=>"Select A Month",
- "01"=>"January",
- "02"=>"February",
- "03"=>"March",
- "04"=>"April",
- "05"=>"May",
- "06"=>"June",
- "07"=>"July",
- "08"=>"August",
- "09"=>"September",
- "10"=>"October",
- "11"=>"November",
- "12"=>"December"
- );
- break;
- case "timestamp":
- case "datetime":
- require_once("form_date.php");
- $return["TYPE"] = "custom";
- $return["CustomClass"] = "form_date_class";
- $return["VALUE"] = 'now';
- $return["ChooseControl"] = 1;
- $return["Format"] = "{day}/{month}/{year}";
- $return["Months"] = array(
- ""=>"Select A Month",
- "01"=>"January",
- "02"=>"February",
- "03"=>"March",
- "04"=>"April",
- "05"=>"May",
- "06"=>"June",
- "07"=>"July",
- "08"=>"August",
- "09"=>"September",
- "10"=>"October",
- "11"=>"November",
- "12"=>"December"
- );
- break;
- case "enum":
- $return["TYPE"] = "select";
- $options = & $return["OPTIONS"];
- $return["OPTIONS"][""] = "Select One";
- $max = strlen($extra);
- $buf = "";
- for($i=0; $i < $max; $i++)
- switch ( $extra[$i] ) {
- case "'":
- case '"':
- $end = $extra[$i++];
- for(;$i < $max && $extra[$i] != $end; $i++) {
- if ( $extra[$i] == "\\") {
- $buf .= $extra[$i+1];
- $i++;
- continue;
- }
- $buf .= $extra[$i];
- }
- break;
- case ",":
- $options[$buf] = $buf;
- $buf = "";
- break;
- }
- if ( $buf!='') {
- $return["OPTIONS"][$buf] = $buf;
- }
- break;
- default:
- $return["TYPE"] = "text";
- break;
- }
- return $return;
- }
- }
- class cruddyMysqlAdmin extends cruddyMysql {
- function cruddyMysqlAdmin() {
- if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
- $this->isWindows = true;
- $this->systemDirectorySeparator = '\\';
- } else {
- $this->isWindows = false;
- $this->systemDirectorySeparator = '/';
- }
- $this->paintedHead = false;
- $this->adminFile = getcwd().$this->systemDirectorySeparator."configurations".$this->systemDirectorySeparator."crud_".$_SERVER['SERVER_NAME']."_".ABS_PATH_HASH.".config.php";
- $this->functionsFile = getcwd().$this->systemDirectorySeparator."configurations".$this->systemDirectorySeparator."crud_".$_SERVER['SERVER_NAME']."_".ABS_PATH_HASH.".custom.functions.php";
- $this->functionsDrawFile = getcwd().$this->systemDirectorySeparator."configurations".$this->systemDirectorySeparator."crud_".$_SERVER['SERVER_NAME']."_".ABS_PATH_HASH.".draw.functions.php";
- $this->databaseConnectionFile = getcwd().$this->systemDirectorySeparator."configurations".$this->systemDirectorySeparator."crud_".$_SERVER['SERVER_NAME']."_".ABS_PATH_HASH.".connections.php";
- if ($this->adminDBExists()) {
- $this->currentAdminDB = $this->readAdminDB();
- }
- $this->steps[1] = 'initialize_server';
- $this->steps[2] = 'select_database';
- $this->steps[3] = 'select_tables';
- $this->steps[4] = 'select_groups';
- $this->steps[5] = 'select_roles';
- $this->steps[6] = 'select_users';
- $this->steps[7] = 'select_theme';
- $this->cruddyAdministrator = (isset($_COOKIE['current_role'])) ? $this->currentAdminDB['crud']['roles'][$_COOKIE['current_role']]['admin_role'] : false;
- $this->dateTime = date("Y-m-j H:i:s");
- // -- update these to whayou want your get string to look like with concatenated TABLE by the time the user clicks
- $this->actionTypes = array();
- $this->actionTypes['new'] = "new_"; // + {TABLENAME} will be concatenated to match the action
- $this->actionTypes['delete'] = "delete_"; // + {TABLENAME}
- $this->actionTypes['update'] = "update_"; // + {TABLENAME}
- $this->actionTypes['read'] = "show_"; // + {TABLENAME}
- $this->actionTypes['view'] = "view_"; // + {TABLENAME}
- $this->actionTypes['order_field'] = "sort_by"; // no additional
- $this->actionTypes['order_direction'] = "direction"; // no additional
- $this->actionTypes['page'] = "page"; // no additional
- $this->tableControlDefaults = array();
- $this->tableControlDefaults[EDIT_TEXT] = "Edit";
- $this->tableControlDefaults[DELETE_TEXT] = "Delete";
- $this->tableControlDefaults[ADD_TEXT] = "Add New {table_desc}";
- $this->tableControlDefaults[TABLE_TEXT] = "{table_desc} Administration";
- $this->tableControlDefaults[VIEW_TEXT] = "View";
- $this->tableControlDefaults[SEARCH_TEXT] = "Search";
- $this->tableControlDefaults[OBJECT_DELETE_CHECK_CONSTRAINTS] = 0;
- $this->tableControlDefaults[OBJECT_HIDE_DELETE_LINK] = 0;
- $this->tableControlDefaults[OBJECT_HIDE_EDIT_LINK] = 0;
- $this->tableControlDefaults[OBJECT_HIDE_NEW_LINK] = 0;
- $this->tableControlDefaults[OBJECT_HIDE_VIEW_LINK] = 0;
- $this->tableControlDefaults[OBJECT_HIDE_SEARCH_LINK] = 0;
- $this->tableControlDefaults[OBJECT_HIDE_DETAILS_LINK] = 0;
- $this->tableControlDefaults[OBJECT_DELETE_CHECK_CONSTRAINTS] = 0;
- $this->tableControlDefaults[OBJECT_PAGING] = 1;
- $this->tableControlDefaults[OBJECT_ACTIONS] = $this->actionTypes;
- $this->tableControlDefaults[REQUIRED_TEXT] = "*";
- $this->tableControlDefaults[OBJECT_PAGING_NUM_ROWS_PER_PAGE] = 10;
- $this->tableControlDefaults[OBJECT_PAGING_SCROLL] = 5;
- $this->tableControlType = array();
- $this->tableControlType[0]['desc'] = "Table Name";
- $this->tableControlType[0]['type'] = "";
- $this->tableControlType[OBJECT_DESC]['desc'] = "Table Desc.";
- $this->tableControlType[OBJECT_DESC]['type'] = "text";
- $this->tableControlType[TABLE_TEXT]['desc'] = "Table Name Text";
- $this->tableControlType[TABLE_TEXT]['type'] = "text";
- $this->tableControlType[EDIT_TEXT]['desc'] = "Edit Link Text or Image Src";
- $this->tableControlType[EDIT_TEXT]['type'] = "text";
- $this->tableControlType[ADD_TEXT]['desc'] = "Add Link Text or Image Src";
- $this->tableControlType[ADD_TEXT]['type'] = "text";
- $this->tableControlType[VIEW_TEXT]['desc'] = "View Link Text or Image Src";
- $this->tableControlType[VIEW_TEXT]['type'] = "text";
- $this->tableControlType[SEARCH_TEXT]['desc'] = "Search Link Text or Image Src";
- $this->tableControlType[SEARCH_TEXT]['type'] = "text";
- $this->tableControlType[DELETE_TEXT]['desc'] = "Delete Link Text or Image Src";
- $this->tableControlType[DELETE_TEXT]['type'] = "text";
- $this->tableControlType[OBJECT_DELETE_CHECK_CONSTRAINTS]['desc'] = "Referential Integrity<br/>On Same Fields?";
- $this->tableControlType[OBJECT_DELETE_CHECK_CONSTRAINTS]['type'] = "checkbox";
- /*$this->tableControlType[OBJECT_PK]['desc'] = "Primary Key";
- $this->tableControlType[OBJECT_PK]['type'] = "text";*/
- $this->tableControlType[OBJECT_DEFAULT_ORDER]['desc'] = "Default Order<br/>{FIELDNAME} DESC/ASC";
- $this->tableControlType[OBJECT_DEFAULT_ORDER]['type'] = "text";
- $this->tableControlType[OBJECT_READ_FILTER]['desc'] = "WHERE Clause Filter On Read";
- $this->tableControlType[OBJECT_READ_FILTER]['type'] = "text";
- $this->tableControlType[OBJECT_FILTER_DESC]['desc'] = "Description of Filter";
- $this->tableControlType[OBJECT_FILTER_DESC]['type'] = "text";
- $this->tableControlType[OBJECT_HIDE_NEW_LINK]['desc'] = "Hide \"Create\" Link";
- $this->tableControlType[OBJECT_HIDE_NEW_LINK]['type'] = "checkbox";
- $this->tableControlType[OBJECT_HIDE_DELETE_LINK]['desc'] = "Hide \"Delete\" Link";
- $this->tableControlType[OBJECT_HIDE_DELETE_LINK]['type'] = "checkbox";
- $this->tableControlType[OBJECT_HIDE_EDIT_LINK]['desc'] = "Hide \"Edit\" Link";
- $this->tableControlType[OBJECT_HIDE_EDIT_LINK]['type'] = "checkbox";
- $this->tableControlType[OBJECT_HIDE_VIEW_LINK]['desc'] = "Hide \"View\" Link";
- $this->tableControlType[OBJECT_HIDE_VIEW_LINK]['type'] = "checkbox";
- $this->tableControlType[OBJECT_HIDE_SEARCH_LINK]['desc'] = "Hide \"Search\…
Large files files are truncated, but you can click here to view the full file