Commit 2ddd6e41 authored by Leif Andersson's avatar Leif Andersson
Browse files

Gjorde kompatibelt med cmsms version 2.

parent 97fdb08a
......@@ -11,19 +11,11 @@
* API, and that everything's safe to continue:
*/
// require_once 'lib/class.Group.php';
if (!isset($gCms)) exit;
//if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
//echo '<pre>'; print_r($params); echo '</pre>';
/**
* For separated methods, you won't be able to do permission checks in
* the DoAction method, so you'll need to do them as needed in your
* method:
*/
/* if (! $this->CheckPermission('Use ReglerAddress')) { */
/* return $this->DisplayErrorPage($id, $params, $returnid, */
/* 'ReglerAddress access denied.'); */
/* } */
$canChangeRecord = $this->CheckPermission('Use ReglerAddress');
/**
* After this, the code is identical to the code that would otherwise be
......@@ -31,11 +23,10 @@ $canChangeRecord = $this->CheckPermission('Use ReglerAddress');
*/
$groups = Groups::getGroupList();
//echo '<pre>'; print_r($groups); echo '</pre>'; exit;
$addrDB = AddressDB::getDB();
$smarty = $this->smarty;
// echo '<pre>'; print_r($params); echo '</pre>';
$place = $this->CreateFormStart($id, 'defaultadmin', $returnid);
$smarty->assign('start_form', $place);
......
<?php
if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
//echo '<pre>'; print_r($params); echo '</pre>';
$ID = $params['ID'];
......
......@@ -6,15 +6,15 @@ class AddressDB {
private static $database = 'NyAdresser';
private function __construct() {
global $gCms;
if (!isset($gCms)) exit;
$config =& $gCms->GetConfig();
if( !defined('CMS_VERSION') ) exit;
$config = cms_utils::get_config();
$this->PDB = ADONewConnection($config['dbms'],
'pear:date:extend:transaction');
$result = $this->PDB->Connect($config['db_hostname'],
$config['db_username'],
$config['db_password'],
self::$database);
if ($result) {
$result = $this->PDB->Execute("SET NAMES 'utf8'");
} else {
......@@ -24,6 +24,7 @@ class AddressDB {
}
public static function getDB() {
if( !defined('CMS_VERSION') ) exit;
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
......@@ -32,6 +33,7 @@ class AddressDB {
}
public static function getFields($tableName) {
if( !defined('CMS_VERSION') ) exit;
$db = self::getDB();
$query = 'select column_name from information_schema.columns where '
. 'table_schema="'. self::$database . '" and table_name=?';
......
......@@ -45,7 +45,7 @@ EOS;
private static $list = array();
public function __construct($param = NULL) {
global $gCms; if (!isset($gCms)) exit;
// global $gCms; if (!isset($gCms)) exit;
if (!isset(self::$groupFields)) {
self::$groupFields = AddressDB::getFields('Grupper');
}
......@@ -109,14 +109,19 @@ EOS;
public static function getGroupList() {
if (count(self::$list) > 0) return self::$list;
global $gCms; if (!isset($gCms)) exit;
// global $gCms; if (!isset($gCms)) exit;
$c = __CLASS__;
$db = AddressDB::getDB();
// echo '<pre>'; print_r($db); echo '</pre>';
$result = $db->Execute(self::$queryList,array());
//echo '<pre>'; print_r($result); echo '</pre>';
if ($result === false) { die("Database error!<br>" . $db->ErrorMsg());}
while ($row = $result->FetchRow()) {
// echo '<pre>'; print_r($row); echo '</pre>';
self::$list[] = new $c($row);
}
//echo '<pre>'; print_r(self::$list); echo '</pre>';
return self::$list;
}
......
......@@ -33,7 +33,8 @@ EOS;
private static $personFields;
public function __construct($param = NULL) {
global $gCms; if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
// global $gCms; if (!isset($gCms)) exit;
if (!isset(self::$personFields)) {
self::$personFields = AddressDB::getFields('Adresser');
}
......@@ -55,7 +56,8 @@ EOS;
}
private function fromDB($adressID) {
global $gCms; if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
// global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
$values = array($adressID);
$result = $db->Execute(self::$queryOne,$values);
......@@ -69,7 +71,7 @@ EOS;
$row = $result->FetchRow();
$nn = self::$personFields;
foreach ($nn as $field) {
if (isset($row[$field])) $this->$field = $row[$field];
if (isset($row[$field])) $this->$field = $row[$field];
}
break;
default:
......@@ -81,7 +83,8 @@ EOS;
}
private function getGroups($adressID) {
global $gCms; if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
//global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
$values = array($adressID);
$result = $db->Execute(self::$queryGroups,$values);
......@@ -92,6 +95,7 @@ EOS;
}
private function createRecord() {
if( !defined('CMS_VERSION') ) exit;
$db = AddressDB::getDB();
$query = 'insert into Adresser set Andrad=null';
// $values = array('Förnamn');
......@@ -103,7 +107,8 @@ EOS;
public function updateRecord() {
global $gCms; if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
// global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
$query = 'update Adresser set ';
$qfields = array(); $values = array();
......@@ -127,7 +132,8 @@ EOS;
}
public static function searchPersons($formValues) {
global $gCms; if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
// global $gCms; if (!isset($gCms)) exit;
$andQuery = array(); $orQuery = '';
$andValues = array(); $orValues = array();
foreach ($formValues as $key => $value) {
......@@ -177,7 +183,8 @@ EOS;
return $records;
}
public static function getGroupMembers($groupID) {
global $gCms; if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
// global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
$class = __CLASS__;
$records = array();
......@@ -187,7 +194,7 @@ EOS;
while ($row = $result->FetchRow()) {
$person = new $class();
foreach ($row as $key => $value) {
$person->$key = $value;
$person->$key = $value;
}
$records[] = $person;
}
......@@ -195,7 +202,8 @@ EOS;
}
public static function deleteRecord($ID = null) {
global $gCms; if (!isset($gCms)) exit;
if( !defined('CMS_VERSION') ) exit;
// global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
if (is_null($ID)) die('Strange error in deleteRecord. No ID.'.PHP_EOL);
$values = array($ID);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment