function updateSchemaAction()
 {
     try {
         $apiID = $this->_request->getParam(api);
         $api = new Api_Model_Profile();
         $api->find($apiID);
         $sql = $api->sql;
         $conn = App_Env::getDb();
         $dbh = $conn->getConnection();
         print_r($dbh);
         $sth = $dbh->prepare($sql);
         $sth->execute();
         $colcount = $sth->columnCount();
         $typelist = array("LONG" => 'int', "VAR_STRING" => 'string', 'DATETIME' => 'datetime', 'BLOB' => 'text', 'DATE' => 'date');
         $inputlist = array("LONG" => 'text', "VAR_STRING" => 'text', 'DATETIME' => 'text', 'BLOB' => 'textarea', 'DATE' => 'datepicker');
         for ($i = 0; $i < $colcount; $i++) {
             $coll = $sth->getColumnMeta($i);
             $collName = $coll['name'];
             $propName = strtolower($collName);
             $propName = str_replace("_", " ", $propName);
             $propName = ucwords($propName);
             $propName = str_replace(" ", "", $propName);
             $propName = lcfirst($propName);
             $type = $coll['native_type'];
             if ($type == '') {
                 $type = 'text';
             }
             $schema = new Api_Model_Service_Schema();
             $result = $schema->fetchRow($schema->select()->where('attribute_name=?', $propName)->where('api_id=?', $apiID));
             if (trim($result->id) == '') {
                 $schema->setApiId($apiID)->setAttributeName($propName)->setColumnName($collName)->setType($typelist)->save();
             }
         }
         $this->_helper->redirector('index', null, null, array('api' => $apiID, 'info' => 101));
     } catch (Exception $e) {
         $this->_helper->redirector('index', null, null, array('api' => $apiID, 'info' => $e->getMessage()));
         echo "ERROR" . $e->getMessage();
     }
 }
 function syncDbAction()
 {
     $this->_helper->layout()->disableLayout();
     $modelName = $modelname = $this->_request->getParam("model", '');
     $configXml = App_Model_Config::get($modelName)->getConfigXML();
     $modelConfig = $configXml->production->classes->{$modelName};
     $table = $modelConfig->table;
     $conn = App_Env::getDb();
     $dbh = $conn->getConnection();
     // print_r($DB);
     $sth = $dbh->prepare('SELECT * FROM ' . $table);
     $sth->execute();
     $colcount = $sth->columnCount();
     $typelist = array("LONG" => 'int', "VAR_STRING" => 'string', 'DATETIME' => 'datetime', 'BLOB' => 'text', 'DATE' => 'date');
     $inputlist = array("LONG" => 'text', "VAR_STRING" => 'text', 'DATETIME' => 'text', 'BLOB' => 'textarea', 'DATE' => 'datepicker');
     for ($i = 0; $i < $colcount; $i++) {
         $coll = $sth->getColumnMeta($i);
         $collName = $coll['name'];
         $propName = strtolower($collName);
         $propName = str_replace("_", " ", $propName);
         $propName = ucwords($propName);
         $propName = str_replace(" ", "", $propName);
         $propName = lcfirst($propName);
         $type = $coll['native_type'];
         if ($type == '') {
             $type = 'text';
         }
         //	print_r($coll);
         $propNode = $doc->createElement("prop");
         $formNode = $doc->createElement("field");
         $gridNode = $doc->createElement("field");
         $propNode->setAttribute('name', $propName);
         $propNode->setAttribute('column', $collName);
         $propNode->setAttribute('label', $propName);
         $propNode->setAttribute('sqltype', $type);
         $propNode->setAttribute('type', isset($typelist[$type]) ? $typelist[$type] : $type);
         $propNode->setAttribute('input', $inputlist[$type]);
         if (in_array("not_null", $coll['flags'])) {
             $propNode->setAttribute('required', 'false');
         }
         if ($coll['len'] < 4 and $typelist[$type] == 'int') {
             $propNode->setAttribute('input', 'spin');
         }
         if (in_array("primary_key", $coll['flags'])) {
             $propNode->setAttribute('pk', 'true');
             $propNode->setAttribute('pk', 'true');
             $propNode->setAttribute('name', 'id');
             if ($typelist[$type] == 'int') {
                 $propNode->setAttribute('form', 'false');
                 $propNode->setAttribute('autoIncrement', 'true');
             } else {
                 $propNode->setAttribute('autoIncrement', 'false');
             }
         }
     }
 }
 function uploadfileAction()
 {
     $this->disableLayout();
     //ini_set("display_errors", 1);
     $arrayErrorCode = array(UPLOAD_ERR_INI_SIZE => "UPLOAD_ERR_INI_SIZE", UPLOAD_ERR_FORM_SIZE => "UPLOAD_ERR_FORM_SIZE", UPLOAD_ERR_PARTIAL => "UPLOAD_ERR_PARTIAL", UPLOAD_ERR_NO_FILE => "UPLOAD_ERR_NO_FILE", UPLOAD_ERR_NO_TMP_DIR => "UPLOAD_ERR_NO_TMP_DIR", UPLOAD_ERR_CANT_WRITE => "UPLOAD_ERR_CANT_WRITE", UPLOAD_ERR_EXTENSION => "UPLOAD_ERR_EXTENSION", UPLOAD_ERR_EXTENSION => "UPLOAD_ERR_EXTENSION");
     sleep(3);
     $folder1 = 'eauditor';
     //strtolower($_SESSION['CollegeShortName']);
     $folder2 = str_replace("-", "", strtolower($this->_request->getParam('systemfolder', '')));
     $folderid = $this->_request->getParam('folder', '');
     // (isset($_REQUEST['folder']))? $_REQUEST['folder'] : '';
     if ($folderid == '') {
         $folderid = $this->_request->getParam('folderid', '1');
         isset($_REQUEST['folderid']) ? $_REQUEST['folder'] : '';
     }
     $file_show = $_FILES['fileupload']['name'];
     // debug($file_show)  ;
     //$fileRealname = $file_show;
     // echo $file_show;
     $file = $file_show;
     //iconv('UTF-8','TIS-620',$file_show);
     $real_name_in_db = $file;
     $url_save_in_db = "/docs/files/" . $folder1 . "/" . $folder2 . "/" . $file;
     $real_url_save_in_db = $url_save_in_db;
     $file_replace = $this->clean_filename($file);
     //$file_replace = iconv("TIS-620","UTF-8", $file_replace) ;
     // debug($file_replace)  ;
     $conn = App_Env::getDb();
     $sql = "SELECT COUNT(*) FROM sys_files WHERE FILE_REAL_NAME LIKE '{$file_show}' ";
     //debug($sql);
     $filecount = (int) $conn->fetchone($sql);
     //debug( "COUNT = ".$filecount);
     if ($filecount > 0) {
         // debug( "line 80 :filename = ".$filename);
         $fileNextIndex = $filecount + 1;
         $fileRename = $this->clean_filename($file_show, $filecount);
         $file_show = $fileRename;
         // debug( "line 90 :fileRename = ".$fileRename);
     } else {
         $fileRename = $this->clean_filename($file_show);
         $file_show = $fileRename;
     }
     $typefile = $_FILES['fileupload']['type'];
     $sizefile = $_FILES['fileupload']['size'];
     //$tempfile = "file/".date("Y-m-d")."-".$file;
     $url = "/docs/files/" . $folder1 . "/" . $folder2 . "/" . $file_show;
     $url_save_in_db = "/docs/files/" . $folder1 . "/" . $folder2 . "/" . $fileRename;
     $structure = str_replace("\\", "/", UPLOAD_PATH . $folder1 . "/" . $folder2);
     //$structure = $_SERVER ['DOCUMENT_ROOT'] . '/file/' . $folderName;
     echo UPLOAD_PATH;
     if (!is_dir($structure)) {
         @mkdir($structure, 0777, true);
     }
     $tempfile_show = $structure . "/" . urlencode($file_show);
     $tempfile = $structure . "/" . $fileRename;
     $errorCode = $_FILES['fileupload']['error'];
     $this->view->errorCode = $errorCode;
     $id = uniqid();
     if ($errorCode === UPLOAD_ERR_OK) {
         try {
             // $newdate =date( 'y-m-d H:i:s' );
             //  $newdatestr = $newdate->format ( 'y-m-d H:i:s' );
             $filedata = array('ID' => $id, 'NAME' => $fileRename, 'TYPE' => $typefile, 'SIZE' => $sizefile, 'PATH' => $tempfile, 'URL' => $url_save_in_db, 'IS_PUBLIC' => 1, 'FILE_REAL_URL' => $real_url_save_in_db, 'FILE_REAL_NAME' => $real_name_in_db, 'folder_id' => $folderid);
             $file = new Sys_Model_File();
             $file->setId($id)->setName($fileRename)->setType($typefile)->setSize($sizefile)->setPath($tempfile)->setUrl($url_save_in_db)->setIsPublic(1)->setIsActive(1)->setFileRealName($real_name_in_db)->setFileRealUrl($real_url_save_in_db)->setFolderId($folderid);
             $this->view->file = $file->save();
         } catch (Exception $e) {
             $error_message = $e->getMessage();
             $this->view->error_message = $error_message;
         }
         move_uploaded_file($_FILES['fileupload']['tmp_name'], $tempfile);
         //copy($_FILES['fileupload']['tmp_name'],$tempfile);
     } else {
         $error_message = $this->file_upload_error_message($errorCode);
         $this->view->errorCode = $arrayErrorCode[$errorCode];
         $this->view->errorCode = errorCode;
     }
 }
示例#4
0
 public function isExists($propName, $val = null)
 {
     if (is_array($propName)) {
         $select = $this->select();
         foreach ($propName as $data) {
             $col = $this->getMapper()->getDbColumn($data['col']);
             $val = $data['val'];
             $operator = trim($data['operator']);
             if ($val == 'ISNULL') {
                 $select->where("{$col} IS NULL");
             } elseif ($operator != '') {
                 $select->where("{$col} {$operator} '{$val}'");
             } else {
                 $select->where("{$col}=?", $val);
             }
         }
         $select->limit(1);
     } elseif ($val != null) {
         $col = $this->getMapper()->getDbColumn($propName);
         $select = $this->select()->where("{$col}=?", $val)->limit(1);
     } else {
         die($this->_modelName . " {$propName} val is null");
     }
     //die("SELECT count(*) AS Counter FROM (". $select .") ddxx");
     $db = App_Env::getDb();
     //if($propName == 'questionId')
     //die ("SELECT count(*) AS Counter FROM (". $select .") ddxx");
     $result = $db->fetchOne(" SELECT count(*) AS Counter FROM (" . $select . ") ddxx");
     return (int) $result > 0 ? true : false;
 }
示例#5
0
 /**
  * Fetch all guestbook entries
  *
  * @return array
  */
 public function fetchAll($where = null, $order = null, $count = null, $offset = null)
 {
     //$time = microtime_float();
     //exit();
     /*
     if(is_string($where)){
     	$where = explode("WHERE", $where); //Zend_Db_Select::
     }else{
     echo 	$where->getPart( Zend_Db_Select::ORDER );
     }
     if($where ){
     	print_r($where);
     	echo 	$where->getPart( Zend_Db_Select::WHERE );
     }
     */
     $model = $this->getModel();
     //die( "xx".get_class($model) );
     $config = $this->getModelConfig();
     $modelName = get_class($model);
     //$this->getModel()->getModelName();
     // die($modelName);
     if ($model->getBaseSQL() != '') {
         $sql = $model->getBaseSQL();
         $sqlselect = " SELECT * FROM ( {$sql} ) tttt ";
         if ($where instanceof Zend_Db_Select) {
             $dbselect = $where;
             $where = $dbselect->getPart(Zend_Db_Select::WHERE);
             $orders = $dbselect->getPart(Zend_Db_Select::ORDER);
             $count = $dbselect->getPart(Zend_Db_Select::LIMIT_COUNT);
             $offet = $dbselect->getPart(Zend_Db_Select::LIMIT_OFFSET);
             if (count($where) > 0) {
                 $sqlselect .= " WHERE " . join(" ", $where);
             }
             if (count($orders) > 0) {
                 $orderby = array();
                 foreach ($orders as $order) {
                     $orderby[] = $order[0] . ' ' . $order[1];
                 }
                 $sqlselect .= " ORDER BY " . join(",", $orderby);
             }
             if ($count != 0) {
                 $sqlselect .= " LIMIT {$offet},{$count} ";
             }
         } else {
             if ($where != '') {
                 $sqlselect .= " where " . $where;
             }
             if ($order != null) {
                 $sqlselect .= " ORDER BY {$order} ";
             }
             if ($offset != null) {
                 $sqlselect .= " LIMIT {$offset},99999999 ";
             }
             if ($count != null) {
                 if ($offset == null) {
                     $offset = 0;
                 }
                 $sqlselect .= " LIMIT {$offset},{$count} ";
             }
             //	echo $sqlselect;
         }
         $querytype = 'basesql';
         $cacheId = md5($sqlselect);
     } elseif ($where instanceof Zend_Db_Select) {
         $querytype = 'dbselect';
         $cacheId = md5($where);
     } elseif ($model->isIgnoreDbTable()) {
         $querytype = 'db';
         $cacheId = md5($where);
         //	echo "isIgnoreDbTable".$where;
     } else {
         $sqlwhere = $this->_getSQLOfPart($where, $order, $count, $offset);
         $cacheId = md5($modelName . $sqlwhere);
     }
     //die("[".$sqlwhere."]");
     $entries = false;
     if (CACHE_DB_ENABLED) {
         $cache_dir = PRIVATE_PATH . '/data/cache/' . $model->getModelName();
         if (!is_dir($cache_dir)) {
             @mkdir($cache_dir, 0777, true);
         }
         $backendOptions = array('cache_dir' => $cache_dir);
         $frontendOptions = array('lifetime' => 7200, 'automatic_serialization' => true);
         $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         $entries = $cache->load($cacheId);
     }
     if ($entries === false) {
         switch ($querytype) {
             case 'basesql':
                 //die('basesql');
                 $db = App_Env::getDb();
                 $resultSet = $db->fetchAll($sqlselect);
                 break;
             case 'dbselect':
                 //die('dbselect');
                 $resultSet = $this->getDbTable()->fetchAll($where);
                 break;
             case 'db':
                 //die('db');
                 $db = App_Env::getDb();
                 $db->setFetchMode(Zend_Db::FETCH_BOTH);
                 $resultSet = $db->fetchAll($where);
                 break;
             default:
                 //echo $where ,"<hr/>";
                 //echo $count,"<hr/>";
                 //echo $order,"<hr/>";
                 //echo $offset,"<hr/>";
                 $resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
                 // die('default');
                 break;
         }
         //  print_r($resultSet);
         $entries = array();
         $configProp = $config->prop;
         foreach ($resultSet as $row) {
             $entries[] = $this->bindEntry($modelName, $row);
         }
         //print_r($entries);
         // echo '<br/>fetchall_time:',round(microtime_float() - $time,3,PHP_ROUND_HALF_UP);
         if (CACHE_DB_ENABLED) {
             $cache->save($entries, $cacheId);
         }
     }
     return $entries;
 }