mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 08:34:29 +00:00
Removed Legacy Scripts
This commit is contained in:
@@ -1,246 +0,0 @@
|
||||
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Examples extends CI_Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->load->database();
|
||||
$this->load->helper('url');
|
||||
|
||||
$this->load->library('grocery_CRUD');
|
||||
}
|
||||
|
||||
public function _example_output($output = null)
|
||||
{
|
||||
$this->load->view('example.php', $output);
|
||||
}
|
||||
|
||||
public function offices()
|
||||
{
|
||||
$output = $this->grocery_crud->render();
|
||||
|
||||
$this->_example_output($output);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
|
||||
}
|
||||
|
||||
public function offices_management()
|
||||
{
|
||||
try{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_theme('datatables');
|
||||
$crud->set_table('offices');
|
||||
$crud->set_subject('Office');
|
||||
$crud->required_fields('city');
|
||||
$crud->columns('city', 'country', 'phone', 'addressLine1', 'postalCode');
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
$this->_example_output($output);
|
||||
}catch(Exception $e){
|
||||
show_error($e->getMessage().' --- '.$e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
public function employees_management()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_theme('datatables');
|
||||
$crud->set_table('employees');
|
||||
$crud->set_relation('officeCode', 'offices', 'city');
|
||||
$crud->display_as('officeCode', 'Office City');
|
||||
$crud->set_subject('Employee');
|
||||
|
||||
$crud->required_fields('lastName');
|
||||
|
||||
$crud->set_field_upload('file_url', 'assets/uploads/files');
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
$this->_example_output($output);
|
||||
}
|
||||
|
||||
public function customers_management()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_table('customers');
|
||||
$crud->columns('customername', 'contactlastname', 'phone', 'city', 'country', 'salesrepemployeenumber', 'creditlimit');
|
||||
$crud->display_as('salesrepemployeenumber', 'from Employeer')
|
||||
->display_as('customername', 'Name')
|
||||
->display_as('contactlastname', 'Last Name');
|
||||
$crud->set_subject('Customer');
|
||||
$crud->set_relation('salesrepemployeenumber', 'employees', 'lastname');
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
$this->_example_output($output);
|
||||
}
|
||||
|
||||
public function orders_management()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_relation('customerNumber', 'customers', '{contactLastName} {contactFirstName}');
|
||||
$crud->display_as('customerNumber', 'Customer');
|
||||
$crud->set_table('orders');
|
||||
$crud->set_subject('Order');
|
||||
$crud->unset_add();
|
||||
$crud->unset_delete();
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
$this->_example_output($output);
|
||||
}
|
||||
|
||||
public function products_management()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_table('products');
|
||||
$crud->set_subject('Product');
|
||||
$crud->unset_columns('productDescription');
|
||||
$crud->callback_column('buyPrice', array($this,'valueToEuro'));
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
$this->_example_output($output);
|
||||
}
|
||||
|
||||
public function valueToEuro($value, $row)
|
||||
{
|
||||
return $value.' €';
|
||||
}
|
||||
|
||||
public function film_management()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_table('film');
|
||||
$crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', 'fullname', 'priority');
|
||||
$crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name');
|
||||
$crud->unset_columns('special_features', 'description', 'actors');
|
||||
|
||||
$crud->fields('title', 'description', 'actors', 'category', 'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features');
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
$this->_example_output($output);
|
||||
}
|
||||
|
||||
public function film_management_twitter_bootstrap()
|
||||
{
|
||||
try{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_theme('twitter-bootstrap');
|
||||
$crud->set_table('film');
|
||||
$crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', 'fullname', 'priority');
|
||||
$crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name');
|
||||
$crud->unset_columns('special_features', 'description', 'actors');
|
||||
|
||||
$crud->fields('title', 'description', 'actors', 'category', 'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features');
|
||||
|
||||
$output = $crud->render();
|
||||
$this->_example_output($output);
|
||||
}catch(Exception $e){
|
||||
show_error($e->getMessage().' --- '.$e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
function multigrids()
|
||||
{
|
||||
$this->config->load('grocery_crud');
|
||||
$this->config->set_item('grocery_crud_dialog_forms', true);
|
||||
$this->config->set_item('grocery_crud_default_per_page', 10);
|
||||
|
||||
$output1 = $this->offices_management2();
|
||||
|
||||
$output2 = $this->employees_management2();
|
||||
|
||||
$output3 = $this->customers_management2();
|
||||
|
||||
$js_files = $output1->js_files + $output2->js_files + $output3->js_files;
|
||||
$css_files = $output1->css_files + $output2->css_files + $output3->css_files;
|
||||
$output = "<h1>List 1</h1>".$output1->output."<h1>List 2</h1>".$output2->output."<h1>List 3</h1>".$output3->output;
|
||||
|
||||
$this->_example_output((object)array(
|
||||
'js_files' => $js_files,
|
||||
'css_files' => $css_files,
|
||||
'output' => $output
|
||||
));
|
||||
}
|
||||
|
||||
public function offices_management2()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
$crud->set_table('offices');
|
||||
$crud->set_subject('Office');
|
||||
|
||||
$crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)), site_url(strtolower(__CLASS__."/multigrids")));
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
if ($crud->getState() != 'list') {
|
||||
$this->_example_output($output);
|
||||
} else {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
public function employees_management2()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_theme('datatables');
|
||||
$crud->set_table('employees');
|
||||
$crud->set_relation('officeCode', 'offices', 'city');
|
||||
$crud->display_as('officeCode', 'Office City');
|
||||
$crud->set_subject('Employee');
|
||||
|
||||
$crud->required_fields('lastName');
|
||||
|
||||
$crud->set_field_upload('file_url', 'assets/uploads/files');
|
||||
|
||||
$crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)), site_url(strtolower(__CLASS__."/multigrids")));
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
if ($crud->getState() != 'list') {
|
||||
$this->_example_output($output);
|
||||
} else {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
public function customers_management2()
|
||||
{
|
||||
$crud = new grocery_CRUD();
|
||||
|
||||
$crud->set_table('customers');
|
||||
$crud->columns('customerName', 'contactLastName', 'phone', 'city', 'country', 'salesRepEmployeeNumber', 'creditLimit');
|
||||
$crud->display_as('salesRepEmployeeNumber', 'from Employeer')
|
||||
->display_as('customerName', 'Name')
|
||||
->display_as('contactLastName', 'Last Name');
|
||||
$crud->set_subject('Customer');
|
||||
$crud->set_relation('salesRepEmployeeNumber', 'employees', 'lastName');
|
||||
|
||||
$crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)), site_url(strtolower(__CLASS__."/multigrids")));
|
||||
|
||||
$output = $crud->render();
|
||||
|
||||
if ($crud->getState() != 'list') {
|
||||
$this->_example_output($output);
|
||||
} else {
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Main extends CI_Controller
|
||||
{
|
||||
/**
|
||||
* Load Database und the url-helper
|
||||
**/
|
||||
private function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// Standard Libraries of codeigniter are required
|
||||
$this->load->database();
|
||||
$this->load->helper('url');
|
||||
// Test the grocery CRUD
|
||||
$this->load->library('grocery_CRUD');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the Welcome Page by default
|
||||
* @return void
|
||||
**/
|
||||
public function index()
|
||||
{
|
||||
echo "<h1>Welcome to the world of Codeigniter</h1>";
|
||||
//Just an example to ensure that we get into the function die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test grocery CRUD for tbl_person
|
||||
* @return void
|
||||
**/
|
||||
public function person()
|
||||
{
|
||||
$this->grocery_crud->set_table('tbl_pperson');
|
||||
$output = $this->grocery_crud->render();
|
||||
|
||||
echo "<pre>";
|
||||
print_r($output);
|
||||
echo "</pre>";
|
||||
//die();
|
||||
|
||||
$this->__exampleOutput($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* example Output
|
||||
* @param string $output The HTML-Output from grocery.
|
||||
* @return void
|
||||
**/
|
||||
private function __exampleOutput($output = null)
|
||||
{
|
||||
$this->load->view('our_template.php', $output);
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
<?php
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class ModelTest extends FHC_Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Index Page for this controller.
|
||||
*
|
||||
* Maps to the following URL
|
||||
* http://example.com/index.php/welcome
|
||||
* - or -
|
||||
* http://example.com/index.php/welcome/index
|
||||
* - or -
|
||||
* Since this controller is set as the default controller in
|
||||
* config/routes.php, it's displayed at http://example.com/
|
||||
*
|
||||
* So any other public methods not prefixed with an underscore will
|
||||
* map to /index.php/welcome/<method_name>
|
||||
* @see http://codeigniter.com/user_guide/general/urls.html
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//$this->session->uid='admin'; // Should normaly be set through auth
|
||||
$this->load->model('person/Person_model');
|
||||
$res = $this->Person_model->getPerson(null, 'asdf\' OR person_id=1; SELECT 1; --');
|
||||
var_dump($res->result_object());
|
||||
|
||||
$this->load->model('crm/Prestudent_model');
|
||||
$id=null;
|
||||
|
||||
// Insert PreStudent
|
||||
$data = array
|
||||
(
|
||||
'aufmerksamdurch_kurzbz' => 'k.A.',
|
||||
'person_id' => 1,
|
||||
'studiengang_kz' => 0
|
||||
);
|
||||
$res = $this->Prestudent_model->insert($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval;
|
||||
|
||||
// Update PreStudent
|
||||
$data = array
|
||||
(
|
||||
'zgvort' => 'Wien',
|
||||
'zgvdatum' => '2012-12-12',
|
||||
'facheinschlberuf' => true
|
||||
);
|
||||
$res = $this->Prestudent_model->update($id, $data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval;
|
||||
|
||||
// Replace PreStudent
|
||||
/*$data = array
|
||||
(
|
||||
'prestudent_id' => $id,
|
||||
'zgvmaort' => 'Linz',
|
||||
'zgvmadatum' => '2011-11-11',
|
||||
'facheinschlberuf' => false
|
||||
);
|
||||
$res = $this->Prestudent_model->replace($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval;
|
||||
else
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval;*/
|
||||
|
||||
// Load PreStudent
|
||||
$res = $this->Prestudent_model->load($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
|
||||
// Insert PreStudentStatus
|
||||
$this->load->model('crm/Prestudentstatus_model');
|
||||
$data = array
|
||||
(
|
||||
'prestudent_id' => $id,
|
||||
'status_kurzbz' => 'Interessent',
|
||||
'studiensemester_kurzbz' => 'WS2001',
|
||||
'ausbildungssemester' => 1
|
||||
);
|
||||
$res = $this->Prestudentstatus_model->insert($data);
|
||||
var_dump($res->retval);
|
||||
|
||||
// Load PreStudentStatus
|
||||
$res = $this->Prestudentstatus_model->load($data);
|
||||
var_dump($res->retval->result_object());
|
||||
$res = $this->Prestudentstatus_model->load(array($id,'Interessent', 'WS2001', 1));
|
||||
var_dump($res->retval->result_object());
|
||||
|
||||
// Update PreStudentStatus
|
||||
$res = $this->Prestudentstatus_model->update($data, array
|
||||
(
|
||||
'prestudent_id' => $id,
|
||||
'status_kurzbz' => 'Bewerber',
|
||||
'studiensemester_kurzbz' => 'WS2011',
|
||||
'ausbildungssemester' => 2
|
||||
));
|
||||
var_dump($res->retval);
|
||||
$res = $this->Prestudentstatus_model->update(array($id,'Bewerber', 'WS2011', 2), $data );
|
||||
var_dump($res->retval);
|
||||
|
||||
// Delete PreStudentStatus
|
||||
$res = $this->Prestudentstatus_model->delete($data);
|
||||
var_dump($res->retval);
|
||||
|
||||
// Delete PreStudent
|
||||
$res = $this->Prestudent_model->delete($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
|
||||
$this->load->model('organisation/Organisationseinheit_model');
|
||||
// Insert OE
|
||||
$data = array
|
||||
(
|
||||
'oe_kurzbz' => 'testoe',
|
||||
'bezeichnung' => 'testoe',
|
||||
'organisationseinheittyp_kurzbz' => 'Institut',
|
||||
'standort_id' => null
|
||||
);
|
||||
$res = $this->Organisationseinheit_model->insert($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id = $data['oe_kurzbz'];
|
||||
var_dump($res);
|
||||
|
||||
// Update OE
|
||||
$data = array
|
||||
(
|
||||
'freigabegrenze' => 1234.56,
|
||||
'kurzzeichen' => 'TestOE',
|
||||
'lehre' => false
|
||||
);
|
||||
$res = $this->Organisationseinheit_model->update($id, $data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval;
|
||||
|
||||
// Delete Organisationseinheit
|
||||
$res = $this->Organisationseinheit_model->delete($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
|
||||
$this->load->model('system/Sprache_model');
|
||||
// Insert Sprache
|
||||
$data = array
|
||||
(
|
||||
'sprache' => 'test',
|
||||
'bezeichnung' => "{'testsprache'}",
|
||||
'locale' => 'te_TE',
|
||||
'content' => false
|
||||
);
|
||||
$res = $this->Sprache_model->insert($data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id = $data['sprache'];
|
||||
var_dump($res);
|
||||
|
||||
// Update Sprache
|
||||
$data = array
|
||||
(
|
||||
'index' => 4,
|
||||
'bezeichnung' => "{'TestSprache', 'TestLanguage', 'TestSpanisch'}",
|
||||
'content' => true
|
||||
);
|
||||
$res = $this->Sprache_model->update($id, $data);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
$id=$res->retval; //echo $id;
|
||||
|
||||
// Load Sprache
|
||||
$res = $this->Sprache_model->load($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
{
|
||||
$result = $res->retval->result_object();
|
||||
var_dump($result);
|
||||
var_dump($this->Sprache_model->pgArrayPhp($result[0]->bezeichnung));
|
||||
var_dump($this->Sprache_model->pgBoolPhp($result[0]->content));
|
||||
}
|
||||
|
||||
// Load All Sprache
|
||||
$res = $this->Sprache_model->loadWhere();
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
{
|
||||
var_dump($res->retval);
|
||||
$result = $res->retval->result_object();
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// Delete Sprache
|
||||
$res = $this->Sprache_model->delete($id);
|
||||
if ($res->error)
|
||||
echo 'Error: ',$res->error, ', Code: ',$res->fhcCode,' -> ',$res->msg,': ',$res->retval,'<br/>';
|
||||
else
|
||||
var_dump($res->retval);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class Pages extends CI_Controller {
|
||||
|
||||
public function view($page = 'vilesci')
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -22,15 +22,13 @@ class Redirect extends FHC_Controller
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
// Loads config file fhcomplete
|
||||
$this->config->load('fhcomplete');
|
||||
}
|
||||
|
||||
|
||||
public function redirectByToken($token)
|
||||
{
|
||||
var_dump($token);
|
||||
|
||||
if (isset($token))
|
||||
{
|
||||
redirect($this->config->item('addons_aufnahme_url') . '?token=' . $token);
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/*!
|
||||
* @brief This function sends compute requests to
|
||||
* ZipComp-Task and waits for response:
|
||||
* @image html ZipCmd_ZipComp_Communication.png
|
||||
*
|
||||
* <!-- Hide plantuml commands from Doxygen inside comment.
|
||||
* Note: Use of the Doxygen tag command to hide code in 1.7.3 will hide the Doxygen docs that follow.
|
||||
* Warning: Don't replaced plantuml commands '@' with '\' - it won't work.
|
||||
* @startuml ZipCmd_ZipComp_Communication.png
|
||||
*
|
||||
* ZipCmd -> ZipComp: First Compute Request
|
||||
* ZipCmd <-- ZipComp: First Compute Response
|
||||
*
|
||||
* ZipCmd -> ZipComp: Second Compute Request
|
||||
* ZipCmd <-- ZipComp: Second Compute Response
|
||||
*
|
||||
* @enduml
|
||||
* -->
|
||||
*
|
||||
* @return some value on success.
|
||||
*/
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* @class Rest_server
|
||||
* @brief Rest Server Controller
|
||||
*
|
||||
* A more detailed class description.
|
||||
*/
|
||||
class Rest_server extends FHC_Controller
|
||||
{
|
||||
/**
|
||||
* Index Method for default function.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->load->helper('url');
|
||||
$this->load->view('rest_server');
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Welcome extends CI_Controller {
|
||||
|
||||
/**
|
||||
* Index Page for this controller.
|
||||
*
|
||||
* Maps to the following URL
|
||||
* http://example.com/index.php/welcome
|
||||
* - or -
|
||||
* http://example.com/index.php/welcome/index
|
||||
* - or -
|
||||
* Since this controller is set as the default controller in
|
||||
* config/routes.php, it's displayed at http://example.com/
|
||||
*
|
||||
* So any other public methods not prefixed with an underscore will
|
||||
* map to /index.php/welcome/<method_name>
|
||||
* @see http://codeigniter.com/user_guide/general/urls.html
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->load->view('welcome_message');
|
||||
}
|
||||
}
|
||||
@@ -1,458 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FH-Complete
|
||||
*
|
||||
* @package FHC-Helper
|
||||
* @author FHC-Team
|
||||
* @copyright Copyright (c) 2016 fhcomplete.org
|
||||
* @license GPLv3
|
||||
* @link https://fhcomplete.org
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
//require_once 'include/basis.class.php';
|
||||
|
||||
/**
|
||||
* FHC-Auth Helpers
|
||||
*
|
||||
* @package FH-Complete
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author FHC-Team
|
||||
* @link http://fhcomplete.org/user_guide/helpers/fhcauth_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
//require_once('include/sprache.class.php');
|
||||
|
||||
class basis_db
|
||||
{
|
||||
protected $ci=null;
|
||||
protected $db_result=null;
|
||||
protected $errormsg=null;
|
||||
|
||||
public function __construct($ci)
|
||||
{
|
||||
$this->ci=$ci;
|
||||
|
||||
if (!defined('FHC_INTEGER'))
|
||||
{
|
||||
define('FHC_INTEGER',1);
|
||||
define('FHC_STRING',2);
|
||||
define('FHC_BOOLEAN',3);
|
||||
define('FHC_LANG_ARRAY',4);
|
||||
}
|
||||
}
|
||||
|
||||
public function db_connect()
|
||||
{
|
||||
$conn_str='host='.DB_HOST.' port='.DB_PORT.' dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD;
|
||||
//Connection Herstellen
|
||||
if (DB_CONNECT_PERSISTENT)
|
||||
{
|
||||
if (!basis_db::$db_conn = pg_pconnect($conn_str))
|
||||
die('Fehler beim Oeffnen der Datenbankverbindung');
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!basis_db::$db_conn = pg_connect($conn_str))
|
||||
die('Fehler beim Oeffnen der Datenbankverbindung');
|
||||
}
|
||||
}
|
||||
|
||||
public function db_query($sql)
|
||||
{
|
||||
if ($this->db_result=$this->ci->db->simple_query($sql))
|
||||
return $this->db_result;
|
||||
else
|
||||
{
|
||||
$this->errormsg.='Abfrage in Datenbank fehlgeschlagen! '.$this->db_last_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function db_num_rows($result=null)
|
||||
{
|
||||
if (is_null($result))
|
||||
return pg_num_rows($this->db_result);
|
||||
else
|
||||
return pg_num_rows($result);
|
||||
}
|
||||
|
||||
public function db_fetch_object($result = null, $i=null)
|
||||
{
|
||||
if (is_null($result))
|
||||
{
|
||||
if (is_null($i))
|
||||
return pg_fetch_object($this->db_result);
|
||||
else
|
||||
return pg_fetch_object($this->db_result, $i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_null($i))
|
||||
return pg_fetch_object($result);
|
||||
else
|
||||
return pg_fetch_object($result, $i);
|
||||
}
|
||||
}
|
||||
|
||||
public function db_fetch_row($result = null, $i=null)
|
||||
{
|
||||
if (is_null($result))
|
||||
{
|
||||
if (is_null($i))
|
||||
return pg_fetch_row($this->db_result);
|
||||
else
|
||||
return pg_fetch_row($this->db_result, $i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_null($i))
|
||||
return pg_fetch_row($result);
|
||||
else
|
||||
return pg_fetch_row($result, $i);
|
||||
}
|
||||
}
|
||||
|
||||
public function db_fetch_assoc($result = null, $i=null)
|
||||
{
|
||||
if (is_null($result))
|
||||
{
|
||||
if (is_null($i))
|
||||
return pg_fetch_assoc($this->db_result);
|
||||
else
|
||||
return pg_fetch_assoc($this->db_result, $i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_null($i))
|
||||
return pg_fetch_row($result);
|
||||
else
|
||||
return pg_fetch_row($result, $i);
|
||||
}
|
||||
}
|
||||
|
||||
public function db_result($result = null, $i,$item)
|
||||
{
|
||||
if (is_null($result))
|
||||
{
|
||||
return pg_result($this->db_result, $i,$item);
|
||||
}
|
||||
else
|
||||
{
|
||||
return pg_result($result, $i,$item);
|
||||
}
|
||||
}
|
||||
|
||||
public function db_getResultJSON($result = null)
|
||||
{
|
||||
$rows=array();
|
||||
if (is_null($result))
|
||||
{
|
||||
while ($r = pg_fetch_assoc($this->db_result))
|
||||
$rows[] = $r;
|
||||
|
||||
//print json_encode($rows);
|
||||
}
|
||||
else
|
||||
{
|
||||
pg_result_seek($result, 0);
|
||||
//var_dump($result);
|
||||
while ($r = pg_fetch_assoc($result))
|
||||
{
|
||||
$rows[] = $r;
|
||||
}
|
||||
|
||||
//print json_encode($rows);
|
||||
}
|
||||
return json_encode($rows);
|
||||
}
|
||||
|
||||
public function db_last_error()
|
||||
{
|
||||
return pg_last_error();
|
||||
}
|
||||
|
||||
public function db_affected_rows($result=null)
|
||||
{
|
||||
if (is_null($result))
|
||||
return pg_affected_rows($this->db_result);
|
||||
else
|
||||
return pg_affected_rows($result);
|
||||
}
|
||||
|
||||
public function db_result_seek($result=null, $offset)
|
||||
{
|
||||
if (is_null($result))
|
||||
return pg_result_seek($this->db_result, $offset);
|
||||
else
|
||||
return pg_result_seek($result, $offset);
|
||||
}
|
||||
|
||||
public function db_fetch_array($result=null)
|
||||
{
|
||||
if (is_null($result))
|
||||
return pg_fetch_array($this->db_result);
|
||||
else
|
||||
return pg_fetch_array($result);
|
||||
}
|
||||
|
||||
public function db_num_fields($result=null)
|
||||
{
|
||||
if (is_null($result))
|
||||
return pg_num_fields($this->db_result);
|
||||
else
|
||||
return pg_num_fields($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert den Feldnamen mit index i
|
||||
*/
|
||||
public function db_field_name($result=null, $i)
|
||||
{
|
||||
if (is_null($result))
|
||||
return pg_field_name($this->db_result, $i);
|
||||
else
|
||||
return pg_field_name($result, $i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Speicher wieder Frei.
|
||||
* (ist das sinnvoll wenn es per Value uebergeben wird??)
|
||||
*/
|
||||
public function db_free_result($result = null)
|
||||
{
|
||||
if (is_null($result))
|
||||
{
|
||||
return pg_free_result($this->db_result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return pg_free_result($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert die aktuelle Datenbankversion
|
||||
*/
|
||||
public function db_version()
|
||||
{
|
||||
return pg_version(basis_db::$db_conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escaped Sonderzeichen in Variablen vor der Verwendung in SQL Statements
|
||||
* um SQL Injections zu verhindern
|
||||
*
|
||||
*/
|
||||
public function db_escape($var)
|
||||
{
|
||||
return pg_escape_string($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Null Value Handling und Hochkomma für Inserts / Updates
|
||||
* Wenn die Uebergebe Variable leer ist, wird ein String mit null
|
||||
* zurueckgeliefert, wenn nicht dann wird der string unter Hochkomma zurueckgeliefert
|
||||
* es sei denn qoute=false dann wird nur der String zurueckgeliefert
|
||||
*
|
||||
* @param $var String-Value fuer SQL Request
|
||||
* @return string
|
||||
*/
|
||||
public function db_null_value($var, $qoute=true)
|
||||
{
|
||||
if ($qoute)
|
||||
return ($var!==''?$this->db_qoute($var):'null');
|
||||
else
|
||||
return ($var!==''?$var:'null');
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt einen String unter Hochkomma
|
||||
* @param $var Value fuer Insert/Update
|
||||
* @return value unter Hochkomma
|
||||
*/
|
||||
public function db_qoute($var)
|
||||
{
|
||||
return "'".$var."'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Escaped einen Parameter fuer die Verwendung in Insert/Update SQL Befehlen
|
||||
* Es werden abhaengig vom Typ Hochkomma oder Null hinzugefuegt
|
||||
* @param $var Value der gesetzt werden soll
|
||||
* @param $type Typ des Values (FHC_STRING | FHC_BOOLEAN | FHC_INTEGER | ...)
|
||||
* @param $nullable boolean gibt an ob das Feld NULL sein darf. Wenn true wird
|
||||
* NULL statt einem Leerstring zurueckgeliefert
|
||||
* @return Escapter Value inklusive Hochkomma wenn noetig
|
||||
*
|
||||
* Verwendungsbeispiel:
|
||||
* Update tbl_person set nachname=$this->db_add_param($var)
|
||||
* Update tbl_person set aktiv=$this->db_add_param($var, FHC_BOOL, false)
|
||||
* Update tbl_person set anzahlkinder=$this->db_add_param($var, FHC_INT)
|
||||
*/
|
||||
public function db_add_param($var, $type=FHC_STRING, $nullable=true)
|
||||
{
|
||||
if (($var==='' || is_null($var)) && $type!=FHC_BOOLEAN)
|
||||
{
|
||||
if ($nullable)
|
||||
return 'null';
|
||||
else
|
||||
return "''";
|
||||
}
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case FHC_INTEGER:
|
||||
$var = $this->db_escape($var);
|
||||
if (!is_numeric($var) && $var!=='')
|
||||
die('Invalid Integer Parameter detected:'.$var);
|
||||
$var = $this->db_null_value($var, false);
|
||||
break;
|
||||
|
||||
case FHC_LANG_ARRAY:
|
||||
|
||||
$sprache = new sprache();
|
||||
$sprache->getAll(true);
|
||||
$buf = $var;
|
||||
$var = array();
|
||||
$languages = $sprache->getAllIndexesSorted();
|
||||
|
||||
foreach($languages as $sk => $sp)
|
||||
{
|
||||
if (!$sp || !isset($buf[$sp]))
|
||||
$var[$sk] = "";
|
||||
else
|
||||
$var[$sk] = $this->db_escape($buf[$sp]);
|
||||
}
|
||||
$var = str_replace('\\', '\\\\', $var);
|
||||
$var = str_replace('"', '\\\"', $var);
|
||||
$var = '\'{"' . join('","', $var) . '"}\'';
|
||||
|
||||
break;
|
||||
|
||||
case FHC_BOOLEAN:
|
||||
if ($var===true)
|
||||
$var='true';
|
||||
elseif ($var===false)
|
||||
$var='false';
|
||||
elseif ($var=='' && $nullable)
|
||||
$var = 'null';
|
||||
else
|
||||
die('Invalid Boolean Parameter detected');
|
||||
break;
|
||||
|
||||
case FHC_STRING:
|
||||
default:
|
||||
$var = $this->db_escape($var);
|
||||
$var = $this->db_null_value($var);
|
||||
break;
|
||||
}
|
||||
return $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt aus einem DB-Result-Boolean einen PHP Boolean
|
||||
*/
|
||||
public function db_parse_bool($var)
|
||||
{
|
||||
if ($var=='t')
|
||||
return true;
|
||||
elseif ($var=='f')
|
||||
return false;
|
||||
elseif ($var=='')
|
||||
return '';
|
||||
else
|
||||
die('Invalid DB Boolean. Wrong DB-Engine?');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bereitet ein Array von Elementen auf, damit es in der IN-Klausel eines
|
||||
* Select Befehls verwendet werden kann.
|
||||
*/
|
||||
public function db_implode4SQL($array)
|
||||
{
|
||||
$string = '';
|
||||
foreach($array as $row)
|
||||
{
|
||||
if ($string!='')
|
||||
$string.=',';
|
||||
$string.=$this->db_add_param($row);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt aus einem DB Array ein PHP Array
|
||||
* @param $var DB Result Array Spalte
|
||||
* @return php array
|
||||
*/
|
||||
public function db_parse_array($var)
|
||||
{
|
||||
if ($var == '')
|
||||
return;
|
||||
preg_match_all('/(?<=^\{|,)(([^,"{]*)|\s*"((?:[^"\\\\]|\\\\(?:.|[0-9]+|x[0-9a-f]+))*)"\s*)(,|(?<!^\{)(?=\}$))/i', $var, $matches, PREG_SET_ORDER);
|
||||
$values = array();
|
||||
foreach ($matches as $match)
|
||||
{
|
||||
$values[] = $match[3] != '' ? stripcslashes($match[3]) : (strtolower($match[2]) == 'null' ? null : $match[2]);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt aus einem DB Array ein PHP Array
|
||||
* @param $var DB Result Array Spalte
|
||||
* @return php array
|
||||
*/
|
||||
public function db_parse_lang_array($var)
|
||||
{
|
||||
|
||||
if ($var == '')
|
||||
return;
|
||||
preg_match_all('/(?<=^\{|,)(([^,"{]*)|\s*"((?:[^"\\\\]|\\\\(?:.|[0-9]+|x[0-9a-f]+))*)"\s*)(,|(?<!^\{)(?=\}$))/i', $var, $matches, PREG_SET_ORDER);
|
||||
$values = array();
|
||||
|
||||
$sprache = new sprache();
|
||||
$sprache->loadIndexArray();
|
||||
|
||||
$sprache = new sprache();
|
||||
$sprache->getAll(true);
|
||||
$languages = $sprache->getAllIndexesSorted();
|
||||
|
||||
|
||||
foreach ($matches as $mk => $match)
|
||||
{
|
||||
$values[$languages[$mk+1]] = $match[3] != '' ? stripcslashes($match[3]) : (strtolower($match[2]) == 'null' ? null : $match[2]);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
function indexSort($a, $b)
|
||||
{
|
||||
return strcmp($a->index, $b->index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bereitet ein Array von Elementen auf, damit es in der IN-Klausel eines
|
||||
* Select Befehls verwendet werden kann.
|
||||
*/
|
||||
function dbImplode4SQL($array)
|
||||
{
|
||||
$string = '';
|
||||
|
||||
foreach($array as $row)
|
||||
{
|
||||
if ($string != '')
|
||||
{
|
||||
$string.=',';
|
||||
}
|
||||
$string.=$this->db_add_param($row);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
* =======================================
|
||||
* Author : Slamet Nurhadi
|
||||
* License : NO License
|
||||
* Email : [email protected]
|
||||
*
|
||||
*
|
||||
*
|
||||
* =======================================
|
||||
*/
|
||||
require_once APPPATH."../vendor/easyrdf/easyrdf/lib/EasyRdf.php";
|
||||
|
||||
class RdfLib
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -1,592 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP grocery CRUD
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt).
|
||||
* You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using.
|
||||
* Please see the corresponding license file for details of these licenses.
|
||||
* You are free to use, modify and distribute this software, but all copyright information must remain.
|
||||
*
|
||||
* @package grocery CRUD
|
||||
* @copyright Copyright (c) 2010 through 2012, John Skoumbourdis
|
||||
* @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt
|
||||
* @version 1.4.2
|
||||
* @author John Skoumbourdis <[email protected]>
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Grocery CRUD Model
|
||||
*
|
||||
*
|
||||
* @package grocery CRUD
|
||||
* @author John Skoumbourdis <[email protected]>
|
||||
* @version 1.5.4
|
||||
* @link http://www.grocerycrud.com/documentation
|
||||
*/
|
||||
class Grocery_crud_model extends CI_Model {
|
||||
|
||||
protected $primary_key = null;
|
||||
protected $table_name = null;
|
||||
protected $relation = array();
|
||||
protected $relation_n_n = array();
|
||||
protected $primary_keys = array();
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function db_table_exists($table_name = null)
|
||||
{
|
||||
return $this->db->table_exists($table_name);
|
||||
}
|
||||
|
||||
function get_list()
|
||||
{
|
||||
if ($this->table_name === null)
|
||||
return false;
|
||||
|
||||
$select = "{$this->table_name}.*";
|
||||
|
||||
//set_relation special queries
|
||||
if (!empty($this->relation))
|
||||
{
|
||||
foreach($this->relation as $relation)
|
||||
{
|
||||
list($field_name , $related_table , $related_field_title) = $relation;
|
||||
$unique_join_name = $this->_unique_join_name($field_name);
|
||||
$unique_field_name = $this->_unique_field_name($field_name);
|
||||
|
||||
if (strstr($related_field_title,'{'))
|
||||
{
|
||||
$related_field_title = str_replace(" "," ",$related_field_title);
|
||||
$select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
|
||||
}
|
||||
else
|
||||
{
|
||||
$select .= ", $unique_join_name.$related_field_title AS $unique_field_name";
|
||||
}
|
||||
|
||||
if ($this->field_exists($related_field_title))
|
||||
$select .= ", {$this->table_name}.$related_field_title AS {$this->table_name}.$related_field_title";
|
||||
}
|
||||
}
|
||||
|
||||
//set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables.
|
||||
if (!empty($this->relation_n_n))
|
||||
{
|
||||
$select = $this->relation_n_n_queries($select);
|
||||
}
|
||||
|
||||
$this->db->select($select, false);
|
||||
|
||||
$results = $this->db->get($this->table_name)->result();
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function get_row($table_name = null)
|
||||
{
|
||||
$table_name = $table_name === null ? $this->table_name : $table_name;
|
||||
|
||||
return $this->db->get($table_name)->row();
|
||||
}
|
||||
|
||||
public function set_primary_key($field_name, $table_name = null)
|
||||
{
|
||||
$table_name = $table_name === null ? $this->table_name : $table_name;
|
||||
|
||||
$this->primary_keys[$table_name] = $field_name;
|
||||
}
|
||||
|
||||
protected function relation_n_n_queries($select)
|
||||
{
|
||||
$this_table_primary_key = $this->get_primary_key();
|
||||
foreach($this->relation_n_n as $relation_n_n)
|
||||
{
|
||||
list($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table,
|
||||
$primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table) = array_values((array)$relation_n_n);
|
||||
|
||||
$primary_key_selection_table = $this->get_primary_key($selection_table);
|
||||
|
||||
$field = "";
|
||||
$use_template = strpos($title_field_selection_table,'{') !== false;
|
||||
$field_name_hash = $this->_unique_field_name($title_field_selection_table);
|
||||
if ($use_template)
|
||||
{
|
||||
$title_field_selection_table = str_replace(" ", " ", $title_field_selection_table);
|
||||
$field .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$title_field_selection_table))."')";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field .= "$selection_table.$title_field_selection_table";
|
||||
}
|
||||
|
||||
//Sorry Codeigniter but you cannot help me with the subquery!
|
||||
$select .= ", (SELECT GROUP_CONCAT(DISTINCT $field) FROM $selection_table "
|
||||
."LEFT JOIN $relation_table ON $relation_table.$primary_key_alias_to_selection_table = $selection_table.$primary_key_selection_table "
|
||||
."WHERE $relation_table.$primary_key_alias_to_this_table = `{$this->table_name}`.$this_table_primary_key GROUP BY $relation_table.$primary_key_alias_to_this_table) AS $field_name";
|
||||
}
|
||||
|
||||
return $select;
|
||||
}
|
||||
|
||||
function order_by($order_by , $direction)
|
||||
{
|
||||
$this->db->order_by( $order_by , $direction );
|
||||
}
|
||||
|
||||
function where($key, $value = NULL, $escape = TRUE)
|
||||
{
|
||||
$this->db->where( $key, $value, $escape);
|
||||
}
|
||||
|
||||
function or_where($key, $value = NULL, $escape = TRUE)
|
||||
{
|
||||
$this->db->or_where( $key, $value, $escape);
|
||||
}
|
||||
|
||||
function having($key, $value = NULL, $escape = TRUE)
|
||||
{
|
||||
$this->db->having( $key, $value, $escape);
|
||||
}
|
||||
|
||||
function or_having($key, $value = NULL, $escape = TRUE)
|
||||
{
|
||||
$this->db->or_having( $key, $value, $escape);
|
||||
}
|
||||
|
||||
function like($field, $match = '', $side = 'both')
|
||||
{
|
||||
$this->db->like($field, $match, $side);
|
||||
}
|
||||
|
||||
function or_like($field, $match = '', $side = 'both')
|
||||
{
|
||||
$this->db->or_like($field, $match, $side);
|
||||
}
|
||||
|
||||
function limit($value, $offset = '')
|
||||
{
|
||||
$this->db->limit( $value , $offset );
|
||||
}
|
||||
|
||||
function get_total_results()
|
||||
{
|
||||
//set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables.
|
||||
if (!empty($this->relation_n_n))
|
||||
{
|
||||
$select = "{$this->table_name}.*";
|
||||
$select = $this->relation_n_n_queries($select);
|
||||
|
||||
$this->db->select($select,false);
|
||||
}
|
||||
|
||||
return $this->db->get($this->table_name)->num_rows();
|
||||
}
|
||||
|
||||
function set_basic_table($table_name = null)
|
||||
{
|
||||
if ( !($this->db->table_exists($table_name)) )
|
||||
return false;
|
||||
|
||||
$this->table_name = $table_name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_edit_values($primary_key_value)
|
||||
{
|
||||
$primary_key_field = $this->get_primary_key();
|
||||
$this->db->where($primary_key_field,$primary_key_value);
|
||||
$result = $this->db->get($this->table_name)->row();
|
||||
return $result;
|
||||
}
|
||||
|
||||
function join_relation($field_name , $related_table , $related_field_title)
|
||||
{
|
||||
$related_primary_key = $this->get_primary_key($related_table);
|
||||
|
||||
if ($related_primary_key !== false)
|
||||
{
|
||||
$unique_name = $this->_unique_join_name($field_name);
|
||||
$this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = {$this->table_name}.$field_name",'left');
|
||||
|
||||
$this->relation[$field_name] = array($field_name , $related_table , $related_field_title);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function set_relation_n_n_field($field_info)
|
||||
{
|
||||
$this->relation_n_n[$field_info->field_name] = $field_info;
|
||||
}
|
||||
|
||||
protected function _unique_join_name($field_name)
|
||||
{
|
||||
return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not with a number
|
||||
}
|
||||
|
||||
protected function _unique_field_name($field_name)
|
||||
{
|
||||
return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not with a number
|
||||
}
|
||||
|
||||
function get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit = null, $search_like = null)
|
||||
{
|
||||
$relation_array = array();
|
||||
$field_name_hash = $this->_unique_field_name($field_name);
|
||||
|
||||
$related_primary_key = $this->get_primary_key($related_table);
|
||||
|
||||
$select = "$related_table.$related_primary_key, ";
|
||||
|
||||
if (strstr($related_field_title,'{'))
|
||||
{
|
||||
$related_field_title = str_replace(" ", " ", $related_field_title);
|
||||
$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
|
||||
}
|
||||
else
|
||||
{
|
||||
$select .= "$related_table.$related_field_title as $field_name_hash";
|
||||
}
|
||||
|
||||
$this->db->select($select,false);
|
||||
if ($where_clause !== null)
|
||||
$this->db->where($where_clause);
|
||||
|
||||
if ($where_clause !== null)
|
||||
$this->db->where($where_clause);
|
||||
|
||||
if ($limit !== null)
|
||||
$this->db->limit($limit);
|
||||
|
||||
if ($search_like !== null)
|
||||
$this->db->having("$field_name_hash LIKE '%".$this->db->escape_like_str($search_like)."%'");
|
||||
|
||||
$order_by !== null
|
||||
? $this->db->order_by($order_by)
|
||||
: $this->db->order_by($field_name_hash);
|
||||
|
||||
$results = $this->db->get($related_table)->result();
|
||||
|
||||
foreach($results as $row)
|
||||
{
|
||||
$relation_array[$row->$related_primary_key] = $row->$field_name_hash;
|
||||
}
|
||||
|
||||
return $relation_array;
|
||||
}
|
||||
|
||||
function get_ajax_relation_array($search, $field_name , $related_table , $related_field_title, $where_clause, $order_by)
|
||||
{
|
||||
return $this->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, 10 , $search);
|
||||
}
|
||||
|
||||
function get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause)
|
||||
{
|
||||
if ($where_clause !== null)
|
||||
$this->db->where($where_clause);
|
||||
|
||||
return $this->db->count_all_results($related_table);
|
||||
}
|
||||
|
||||
function get_relation_n_n_selection_array($primary_key_value, $field_info)
|
||||
{
|
||||
$select = "";
|
||||
$related_field_title = $field_info->title_field_selection_table;
|
||||
$use_template = strpos($related_field_title,'{') !== false;;
|
||||
$field_name_hash = $this->_unique_field_name($related_field_title);
|
||||
if ($use_template)
|
||||
{
|
||||
$related_field_title = str_replace(" ", " ", $related_field_title);
|
||||
$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
|
||||
}
|
||||
else
|
||||
{
|
||||
$select .= "$related_field_title as $field_name_hash";
|
||||
}
|
||||
$this->db->select('*, '.$select,false);
|
||||
|
||||
$selection_primary_key = $this->get_primary_key($field_info->selection_table);
|
||||
|
||||
if (empty($field_info->priority_field_relation_table))
|
||||
{
|
||||
if (!$use_template){
|
||||
$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}");
|
||||
}
|
||||
$this->db->where($field_info->primary_key_alias_to_this_table, $primary_key_value);
|
||||
$this->db->join(
|
||||
$field_info->selection_table,
|
||||
"{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}"
|
||||
);
|
||||
$results = $this->db->get($field_info->relation_table)->result();
|
||||
|
||||
$results_array = array();
|
||||
foreach($results as $row)
|
||||
{
|
||||
$results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash};
|
||||
}
|
||||
|
||||
return $results_array;
|
||||
}
|
||||
|
||||
function get_relation_n_n_unselected_array($field_info, $selected_values)
|
||||
{
|
||||
$use_where_clause = !empty($field_info->where_clause);
|
||||
|
||||
$select = "";
|
||||
$related_field_title = $field_info->title_field_selection_table;
|
||||
$use_template = strpos($related_field_title,'{') !== false;
|
||||
$field_name_hash = $this->_unique_field_name($related_field_title);
|
||||
|
||||
if ($use_template)
|
||||
{
|
||||
$related_field_title = str_replace(" ", " ", $related_field_title);
|
||||
$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
|
||||
}
|
||||
else
|
||||
{
|
||||
$select .= "$related_field_title as $field_name_hash";
|
||||
}
|
||||
$this->db->select('*, '.$select,false);
|
||||
|
||||
if ($use_where_clause){
|
||||
$this->db->where($field_info->where_clause);
|
||||
}
|
||||
|
||||
$selection_primary_key = $this->get_primary_key($field_info->selection_table);
|
||||
if (!$use_template)
|
||||
$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
|
||||
$results = $this->db->get($field_info->selection_table)->result();
|
||||
|
||||
$results_array = array();
|
||||
foreach($results as $row)
|
||||
{
|
||||
if (!isset($selected_values[$row->$selection_primary_key]))
|
||||
$results_array[$row->$selection_primary_key] = $row->{$field_name_hash};
|
||||
}
|
||||
|
||||
return $results_array;
|
||||
}
|
||||
|
||||
function db_relation_n_n_update($field_info, $post_data ,$main_primary_key)
|
||||
{
|
||||
$this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key);
|
||||
if (!empty($post_data))
|
||||
$this->db->where_not_in($field_info->primary_key_alias_to_selection_table , $post_data);
|
||||
$this->db->delete($field_info->relation_table);
|
||||
|
||||
$counter = 0;
|
||||
if (!empty($post_data))
|
||||
{
|
||||
foreach($post_data as $primary_key_value)
|
||||
{
|
||||
$where_array = array(
|
||||
$field_info->primary_key_alias_to_this_table => $main_primary_key,
|
||||
$field_info->primary_key_alias_to_selection_table => $primary_key_value,
|
||||
);
|
||||
|
||||
$this->db->where($where_array);
|
||||
$count = $this->db->from($field_info->relation_table)->count_all_results();
|
||||
|
||||
if ($count == 0)
|
||||
{
|
||||
if (!empty($field_info->priority_field_relation_table))
|
||||
$where_array[$field_info->priority_field_relation_table] = $counter;
|
||||
|
||||
$this->db->insert($field_info->relation_table, $where_array);
|
||||
|
||||
}elseif ($count >= 1 && !empty($field_info->priority_field_relation_table))
|
||||
{
|
||||
$this->db->update( $field_info->relation_table, array($field_info->priority_field_relation_table => $counter) , $where_array);
|
||||
}
|
||||
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function db_relation_n_n_delete($field_info, $main_primary_key)
|
||||
{
|
||||
$this->db->where($field_info->primary_key_alias_to_this_table, $main_primary_key);
|
||||
$this->db->delete($field_info->relation_table);
|
||||
}
|
||||
|
||||
function get_field_types_basic_table()
|
||||
{
|
||||
$db_field_types = array();
|
||||
foreach($this->db->query('SELECT column_name AS "Field", data_type AS "Type",
|
||||
CASE WHEN indisprimary THEN '."'PRI'".' WHEN indisunique THEN '."'UNI'".' ELSE null END AS "Key", is_nullable AS "Null", NULL AS "Extra"
|
||||
FROM information_schema.columns
|
||||
JOIN pg_namespace ON (table_schema=nspname)
|
||||
JOIN pg_class ON (pg_class.relnamespace = pg_namespace.oid AND pg_class.oid = table_name::regclass)
|
||||
JOIN pg_attribute ON (pg_attribute.attrelid = pg_class.oid AND attname=column_name)
|
||||
LEFT JOIN pg_index ON (indrelid = pg_class.oid AND
|
||||
pg_attribute.attnum = any(pg_index.indkey))
|
||||
WHERE table_name = '."'{$this->table_name}'")->result() as $db_field_type)
|
||||
{
|
||||
$type = explode("(",$db_field_type->Type);
|
||||
$db_type = $type[0];
|
||||
|
||||
if (isset($type[1]))
|
||||
{
|
||||
if (substr($type[1],-1) == ')')
|
||||
{
|
||||
$length = substr($type[1],0,-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
list($length) = explode(" ",$type[1]);
|
||||
$length = substr($length,0,-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$length = '';
|
||||
}
|
||||
$db_field_types[$db_field_type->Field]['db_max_length'] = $length;
|
||||
$db_field_types[$db_field_type->Field]['db_type'] = $db_type;
|
||||
$db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false;
|
||||
$db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra;
|
||||
$db_field_types[$db_field_type->Field]['db_key'] = $db_field_type->Key;
|
||||
$db_field_types[$db_field_type->Field]['primary_key'] = $db_field_type->Key == 'PRI' ? 1 : 0;
|
||||
}
|
||||
|
||||
$results = $this->db->field_data($this->table_name);
|
||||
foreach($results as $num => $row)
|
||||
{
|
||||
$row = (array)$row;
|
||||
$results[$num] = (object)( array_merge($row, $db_field_types[$row['name']]) );
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
function get_field_types($table_name)
|
||||
{
|
||||
$results = $this->db->field_data($table_name);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
function db_update($post_array, $primary_key_value)
|
||||
{
|
||||
$primary_key_field = $this->get_primary_key();
|
||||
return $this->db->update($this->table_name,$post_array, array( $primary_key_field => $primary_key_value));
|
||||
}
|
||||
|
||||
function db_insert($post_array)
|
||||
{
|
||||
$insert = $this->db->insert($this->table_name,$post_array);
|
||||
if ($insert)
|
||||
{
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function db_delete($primary_key_value)
|
||||
{
|
||||
$primary_key_field = $this->get_primary_key();
|
||||
|
||||
if ($primary_key_field === false)
|
||||
return false;
|
||||
|
||||
$this->db->limit(1);
|
||||
$this->db->delete($this->table_name,array( $primary_key_field => $primary_key_value));
|
||||
if ( $this->db->affected_rows() != 1)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
function db_file_delete($field_name, $filename)
|
||||
{
|
||||
if ( $this->db->update($this->table_name,array($field_name => ''),array($field_name => $filename)) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function field_exists($field,$table_name = null)
|
||||
{
|
||||
if (empty($table_name))
|
||||
{
|
||||
$table_name = $this->table_name;
|
||||
}
|
||||
return $this->db->field_exists($field,$table_name);
|
||||
}
|
||||
|
||||
function get_primary_key($table_name = null)
|
||||
{
|
||||
if ($table_name == null)
|
||||
{
|
||||
if (isset($this->primary_keys[$this->table_name]))
|
||||
{
|
||||
return $this->primary_keys[$this->table_name];
|
||||
}
|
||||
|
||||
if (empty($this->primary_key))
|
||||
{
|
||||
$fields = $this->get_field_types_basic_table();
|
||||
|
||||
foreach($fields as $field)
|
||||
{
|
||||
if ($field->primary_key == 1)
|
||||
{
|
||||
return $field->name;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->primary_key;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($this->primary_keys[$table_name]))
|
||||
{
|
||||
return $this->primary_keys[$table_name];
|
||||
}
|
||||
|
||||
$fields = $this->get_field_types($table_name);
|
||||
|
||||
foreach($fields as $field)
|
||||
{
|
||||
/*if ($field->primary_key == 1)
|
||||
{
|
||||
return $field->name;
|
||||
}*/
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function escape_str($value)
|
||||
{
|
||||
return $this->db->escape_str($value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Welcome to CodeIgniter</title>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#body {
|
||||
margin: 0 15px 0 15px;
|
||||
}
|
||||
|
||||
p.footer {
|
||||
text-align: right;
|
||||
font-size: 11px;
|
||||
border-top: 1px solid #D0D0D0;
|
||||
line-height: 32px;
|
||||
padding: 0 10px 0 10px;
|
||||
margin: 20px 0 0 0;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
<h1>Welcome to CodeIgniter!</h1>
|
||||
|
||||
<div id="body">
|
||||
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
|
||||
|
||||
<p>If you would like to edit this page you'll find it located at:</p>
|
||||
<code>application/views/welcome_message.php</code>
|
||||
|
||||
<p>The corresponding controller for this page is found at:</p>
|
||||
<code>application/controllers/Welcome.php</code>
|
||||
|
||||
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
|
||||
</div>
|
||||
|
||||
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user