コード例 #1
0
ファイル: Database.php プロジェクト: nveeed/ems
 /**
  * @param $array
  * @param $tblName
  * @return bool
  * Saves an array $array to a table $tblName
  * The $array could contain enteries that may not belong to $tblName so we find tableFields first so that only related fields are saved to the db
  */
 public function save($array, $tblName)
 {
     //        $tblFields = array_flip( $db->getTableFieldsList($tblName) );
     $classname = tbl2cls($tblName);
     $arrayToSave = obj2arr($classname::getColumns());
     $dataFound = false;
     foreach ($arrayToSave as $field => $value) {
         if (array_key_exists($field, $array)) {
             $arrayToSave[$field] = $array[$field];
             $dataFound = true;
         } else {
             unset($arrayToSave[$field]);
         }
     }
     if ($dataFound) {
         if (isset($arrayToSave['id']) && !empty($arrayToSave['id'])) {
             //                pr("updating...");
             // i.e. the record already exists, update it
             return $this->update($arrayToSave, $tblName);
         } else {
             //                pr("creating...");
             // i.e. the record does not already exist, create it
             return $this->create($arrayToSave, $tblName);
         }
     }
     return false;
 }
コード例 #2
0
ファイル: TableObject.php プロジェクト: nveeed/ems
 static function linkedClasses()
 {
     global $db;
     $tables = find_in_array($db->getTablesList(), "^" . static::$tablename . "__");
     // $tables: all tables with static::$tablename__ at the start (^)
     // pr($tables);
     $output = array();
     if ($tables) {
         foreach ($tables as $key => $tablename) {
             $output[] = tbl2cls(str_replace(static::$tablename . "__", "", $tablename));
         }
     }
     return $output;
 }
コード例 #3
0
ファイル: bakeModels.php プロジェクト: nveeed/ems
<?php

require_once "../initialize.php";
/**
 * Created by EngrNaveed.
 * Date: 01-Jan-15
 * Time: 5:20 PM
 */
// data
$tablesList = $db->getTablesList('ems');
foreach ($tablesList as $tablename) {
    $fields = $db->getTableColumns($tablename);
    $className = tbl2cls($tablename);
    //starting comments
    $contents = docStart();
    $contents .= "class {$className} extends {$className}Auto{\n";
    $contents .= "\tstatic \$joinedTables = array();\n";
    $contents .= "\tstatic \$childClasses = array();\n";
    $contents .= "\tstatic \$displayFields = array();\n";
    // __construct
    $contents .= "\n\tfunction __construct(\$id = null){\n";
    $contents .= "\t\tparent::__construct(\$id);\n";
    $contents .= "\t}\n";
    // contructor end
    $contents .= "\n\n\n\n}";
    // class end
    // create file
    $file = new File("models/{$className}.php");
    //    $file->setContent($contents);
}
// show in the browser
コード例 #4
0
ファイル: TableColumn.php プロジェクト: nveeed/ems
 public function a_tag($text = "")
 {
     // show displayVal() bt default
     if (!$text) {
         $text = $this->displayVal();
     }
     // a tag will be different for fkeys
     if ($this->isFkey()) {
         $class = $this->fkeyInfo->fClass;
         $recordId = $this->val;
     } else {
         $class = tbl2cls($this->table);
         $recordId = $this->recordId;
     }
     // file to direct to:
     $filename = "recordDetail.php";
     // return tag
     return "<a target='_blank' href='{$filename}?classname={$class}&recordId={$recordId}'>{$text}</a>";
 }
コード例 #5
0
ファイル: list_reportMarkup.php プロジェクト: nveeed/ems
    echo "<th></th>";
    echo "</tr></thead>";
    echo "<tbody>";
    $count = 1;
    foreach ($records as $record) {
        echo "<tr>";
        echo "<td>{$count}</td>";
        $count++;
        foreach ($visibleHeads as $header) {
            if (isset($_GET['classname']) && $_GET['classname'] == "Log_messag") {
                // Log should not be editable
                $val = $record->{$header}->displayVal();
            } else {
                $val = $record->{$header}->getEditableValue();
            }
            echo "<td>{$val}</td>";
        }
        // open link
        $href = "recordDetail.php?classname=" . tbl2cls($record->id->table) . "&recordId=" . $record->id->val;
        $openLink = "<a href='{$href}' target='_blank'>" . icon("folder-open") . "</a>";
        echo "<td class='hidden-print'>{$openLink}</td>";
        echo "</tr>";
    }
    echo "</tbody>";
    echo "</table>";
    echo "</div>";
    // hidden IPs
    $html->echoHiddenInputs($record);
} else {
    echo "<p class='has-error'>No records found. Please check out the filtering options.</p>";
}
コード例 #6
0
ファイル: bakeModelsAuto.php プロジェクト: nveeed/ems
<?php

require_once "../initialize.php";
/**
 * Created by EngrNaveed.
 * Date: 01-Jan-15
 * Time: 5:20 PM
 */
// data
$tablesList = $db->getTablesList('ems');
pr($tablesList);
foreach ($tablesList as $tablename) {
    $fields = $db->getTableColumns($tablename);
    $className = tbl2cls($tablename) . "Auto";
    echo $className . " -<br>";
    //starting comments
    $contents = "<?php\n/**\n * Created by Naveed-ul-Hassan Malik\n * Auto-Generated Using Script On:\n * Date: " . strftime("%a %d-%b-%Y", time() + 5 * 3600) . "\n * Time: " . strftime("%I:%M %p PST", time() + 5 * 3600) . "\n */\n";
    $contents .= "class {$className} extends TableObject{\n";
    $contents .= "\tprotected static \$tablename = '" . $tablename . "';\n";
    // fields declaration
    foreach ($fields as $key => $value) {
        $contents .= "\tpublic \$" . $value->name . ";\n";
    }
    $contents .= "\tstatic \$dbColumns = array('";
    $fieldList = $db->getTableFieldsList($tablename);
    $contents .= join("','", $fieldList);
    $contents .= "');\n";
    // __construct
    $contents .= "\n\tfunction __construct(\$id = null){\n";
    foreach ($fields as $key => $field) {
        $contents .= "\t\t\$this->" . $field->name . " = new TableColumn( '";
コード例 #7
0
ファイル: records_post_handler.php プロジェクト: nveeed/ems
$arrayToSave = null;
$msg = "Successfully Saved to Database.";
$msgType = 'success';
$autoInsertFormIsSubmitted = areSet(array('autoInsertForm', 'classname'), $_POST);
$recordIsBeingEdited = isAjax() && isset($_POST['recordInfo']) && isset($_POST['valueToSave']);
$newRecFormIsSubmitted = isset($_POST['submit']);
$anyFormIsSubmitted = $autoInsertFormIsSubmitted || $recordIsBeingEdited || $newRecFormIsSubmitted;
if ($recordIsBeingEdited) {
    $info = explode('-', decrypt($_POST['recordInfo']));
    //    $info: Array
    //    (
    //        [0] => persons    // table
    //        [1] => cnic       // field
    //        [2] => 13         // id
    //    )
    $classname = tbl2cls($info[0]);
    $objToSave = $classname::findById($info[2]);
    $objToSave->{$info}[1]->val = $_POST['valueToSave'];
} elseif ($newRecFormIsSubmitted) {
    $classname = $_POST['classname'];
    $objToSave = $classname::instantiate($_POST);
}
if ($classname && $objToSave) {
    if ($objToSave->dbSave()) {
        $_POST = array();
        if (!isAjax()) {
            reloadCurrentPage();
        }
    } else {
        $formErrors = $objToSave->getErrors();
        $msg = !empty($formErrors) ? array_shift($formErrors) . ". " : "";
コード例 #8
0
ファイル: records.php プロジェクト: nveeed/ems
<?php

require_once 'html_components/require_comps_start.php';
// handle post requests
require_once "html_components/records_post_handler.php";
// No need to go further if page_id is not provided
if (!isset($_GET['page_id'])) {
    show404();
}
// 1. get crud_page
$crud_page = getCrudPage($_GET['page_id']);
if (!$crud_page) {
    show404();
}
$classname = tbl2cls($crud_page['table_name']);
if ($classname instanceof TableObject) {
}
// find data
$curPage->saveConfig('pagination', true);
if (isset($_POST['q']) && !empty($_POST['q'])) {
    $records = $classname::findByString($_POST['q']);
} else {
    $records = $classname::findAll();
}
//prlq();
//pr($records);
// handle delete requests
require_once "html_components/records_delete_handler.php";
?>

<div class="row">