From f22a427736bb0a1b558298a8d25867f3811bd426 Mon Sep 17 00:00:00 2001 From: Leif Andersson <leif.andersson@control.lth.se> Date: Thu, 3 Sep 2015 16:00:28 +0200 Subject: [PATCH] Added rudimentary action.defaultadmin, class.AddressDB, adminpanel.tpl --- lib/action.defaultadmin.php | 119 ++++++++++++++++++++++++++++++++++++ lib/class.AddressDB.php | 33 ++++++++++ templates/adminpanel.tpl | 9 +++ 3 files changed, 161 insertions(+) create mode 100644 lib/action.defaultadmin.php create mode 100644 lib/class.AddressDB.php create mode 100644 templates/adminpanel.tpl diff --git a/lib/action.defaultadmin.php b/lib/action.defaultadmin.php new file mode 100644 index 0000000..0d1665c --- /dev/null +++ b/lib/action.defaultadmin.php @@ -0,0 +1,119 @@ +<?php +/** + * DisplayAdminPanel($id, $params, $returnid, $message) + * NOT PART OF THE MODULE API + * + */ + +/** + * For separated methods, you'll always want to start with the following + * line which check to make sure that method was called from the module + * API, and that everything's safe to continue: + */ +if (!isset($gCms)) exit; + + +/** + * 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.'); +} + +/** + * After this, the code is identical to the code that would otherwise be + * wrapped in the DisplayAdminPanel() method in the module body. + */ + +if (FALSE == empty($params['active_tab'])) + { + $tab = $params['active_tab']; + } else { + $tab = ''; + } + +//file_put_contents("/tmp/defaultadmin.txt",print_r($params,TRUE)); +$semDB = AddressDB::getDB(); +/* $orderby = ' date desc, start desc'; */ +/* $wheredate = ' date > SUBDATE(CURDATE(), 30) '; */ +/* $currentYear = date('Y'); */ +/* if (isset($params['year'])) { */ +/* $year = $params['year']; */ +/* $yearstart = $semDB->Quote(sprintf('%s-01-01',$year)); */ +/* $yearend = $semDB->Quote(sprintf('%s-12-31',$year)); */ +/* $wheredate = sprintf(' date > %s and date < %s', $yearstart, $yearend); */ +/* $previousYear = $year - 1; */ +/* $nextYear = $year + 1; */ +/* $place = $this->CreateInputSubmit($id, 'year', $previousYear); */ +/* $smarty->assign('previousSelect', $place); */ +/* if ($nextYear <= $currentYear) { */ +/* $place = $this->CreateInputSubmit($id, 'year', $nextYear); */ +/* $smarty->assign('nextSelect', $place); */ +/* } */ +/* } else { */ +/* $place = $this->CreateInputSubmit($id, 'year', $currentYear); */ +/* $smarty->assign('previousSelect', $place); */ +/* } */ + +/* $wheredate = $wheredate . ' and seminars.type=types.id '; */ +/* $records = Seminar::getSeminars($wheredate,$orderby); */ +/* foreach ($records as $rec) { */ +/* $link = $this->CreateFrontendLink($id, $returnid, 'add_edit','%s', */ +/* array('seminarID'=>$rec->id)); */ +/* $rec->setAdminLink($link); */ +/* } */ + + +/* // Expose the list to smarty. Use "by_ref" to save memory. */ +/* $smarty->assign_by_ref('records',$records); */ + +/* // and a count of records */ +/* $smarty->assign('title_num_records', */ +/* $this->Lang('title_num_records',array(count($records)))); */ + + +$place = $this->CreateFormStart($id, 'defaultadmin', $returnid); +$smarty->assign('start_form', $place); +$smarty->assign('end_form', $this->CreateFormEnd()); + +$title_fornamn = 'Förnamn'; +$place = $this->CreateInputText($id,'Fornamn', $fornamn,40); +$input_fornamn = $place; + +$title_efternamn = 'Efternamn'; +$place = $this->CreateInputText($id,'Efternamn', $efternamn,40); +$input_efternamn = $place; + + +/* $place = $this->CreateFormStart($id, 'add_edit', $returnid); */ +/* $smarty->assign('start_form', $place); */ +/* $types = array_flip(Util::$seminarTypes); */ +/* array_shift($types); */ +/* $place = $this->CreateInputSelectList($id,'numericType', */ +/* $types, */ +/* array(1),4,NULL,FALSE); */ +/* $smarty->assign('seminarType', $place); */ +/* $place = $this->CreateInputSubmit($id, 'newSeminar', 'New Seminar'); */ +/* $smarty->assign('submit', $place); */ + +/* if (isset($params['module_message'])) { */ +/* $this->smarty->assign('module_message',$params['module_message']); */ +/* } else { */ +/* $this->smarty->assign('module_message',''); */ +/* } */ + +/* // Display the populated template */ +/* $smarty->assign('end_form', $this->CreateFormEnd()); */ + +/* $place = $this->CreateFormStart($id, 'composeLetter', $returnid); */ +/* $smarty->assign('start_letter_form', $place); */ +/* $place = $this->CreateInputSubmit($id, 'composeLetter', 'Compose Letter'); */ +/* $smarty->assign('submit_letter', $place); */ +/* $smarty->assign('end_letter_form', $this->CreateFormEnd()); */ + +echo $this->ProcessTemplate('adminpanel.tpl'); + +?> \ No newline at end of file diff --git a/lib/class.AddressDB.php b/lib/class.AddressDB.php new file mode 100644 index 0000000..4e5d3f5 --- /dev/null +++ b/lib/class.AddressDB.php @@ -0,0 +1,33 @@ +<?php + +class SeminarDB { + private static $instance; + private $PDB; + private $database = 'addresses'; + + private function __construct() { + global $gCms; + if (!isset($gCms)) exit; + $config =& $gCms->GetConfig(); + $this->PDB = ADONewConnection($config['dbms'], + 'pear:date:extend:transaction'); + $result = $this->PDB->Connect($config['db_hostname'], + $config['db_username'], + $config['db_password'], + $database); + if ($result) { + $result = $this->PDB->Execute("SET NAMES 'utf8'"); + } else { + echo "Database error!<br>" . $this->PDB->ErrorMsg(); + exit; + } + } + + public static function getDB() { + if (!isset(self::$instance)) { + $c = __CLASS__; + self::$instance = new $c; + } + return self::$instance->PDB; + } +} diff --git a/templates/adminpanel.tpl b/templates/adminpanel.tpl new file mode 100644 index 0000000..3af68c8 --- /dev/null +++ b/templates/adminpanel.tpl @@ -0,0 +1,9 @@ +{$start_form} +<table><tbody> +<tr><td style="text-align:right;">{$title_fornamn}</td> + <td>{$input_fornamn}</td></tr> +<tr><td style="text-align:right;">{$title_efternamn}</td> + <td>{$input_efternamn}</td></tr> +</tbody></table> +{$end_form} + -- GitLab