diff options
author | James Bottomley <JBottomley@Parallels.com> | 2013-04-28 09:41:46 -0700 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-04-28 09:41:46 -0700 |
commit | e4315247481abd31a6fcf7f20212906742ac1b24 (patch) | |
tree | 31236436361cd6e52e784c45615042d23ac1a588 | |
parent | f7b42ea5c24eefdb848202d938e773dac27ba4dd (diff) | |
download | asterisk-aastra-e4315247481abd31a6fcf7f20212906742ac1b24.tar.gz |
List handling
Add two classes, one for base list handling and the other for lists
as databases elements within the asterisk server.
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | include/BaseList.class.php | 58 | ||||
-rw-r--r-- | include/DatabaseListManager.class.php | 51 |
2 files changed, 109 insertions, 0 deletions
diff --git a/include/BaseList.class.php b/include/BaseList.class.php new file mode 100644 index 0000000..b3fcedc --- /dev/null +++ b/include/BaseList.class.php @@ -0,0 +1,58 @@ +<?php +## +# Copyright 2013 by James Bottomley +## +# Class implementing a wrapper for List objects +## +require_once('AastraIPPhoneTextMenu.class.php'); + +class BaseList extends AastraIPPhoneTextMenu { + var $data; + var $window = 4; + var $page; + var $title; + var $url; + + function list_scroll_up() { + } + + function __construct($url) { + $this->page = 0; + if (isset($_GET['page'])) { + $this->page = $_GET['page']; + } + $this->url = $url; + parent::__construct(); + } + + function setTitle($title) { + $this->title = $title; + } + + function build() { + $pages = intval((count($this->data)+3)/$this->window); + $down = $this->page + 1 == $pages ? null : $this->url.'&page='.($this->page + 1).'&index='.$this->window; + $up = $this->page == 0 ? null : $this->url.'&page='.($this->page - 1).'&index=0'; + parent::setTitle($this->title.' Page: '.($this->page+1).'/'.$pages); + $this->setStyle('none'); + if ($up) { + $this->setScrollUp($up); + } + if ($down) { + $this->setScrollDown($down); + } + if (isset($_GET['index'])) { + $this->setDefaultIndex($_GET['index']); + } + $this->setUnitScroll(); + $start = $this->page * $this->window; + $end = ($this->page + 1) * $this->window; + if ($end > count($this->data)) { + $end = count($this->data); + } + for($i = $start; $i < $end; $i++) { + $a = $this->data[$i]; + $this->addEntry($a[0], $a[1]); + } + } +} diff --git a/include/DatabaseListManager.class.php b/include/DatabaseListManager.class.php new file mode 100644 index 0000000..b89b58b --- /dev/null +++ b/include/DatabaseListManager.class.php @@ -0,0 +1,51 @@ +<?php +## +# Copyright 2013 by James Bottomley +## +# Class implementing a wrapper for managing lists in the database +## +require_once('BaseList.class.php'); + +class DatabaseListManager extends BaseList { + ## + # hacking inner classes. This list manager should really be + # the inner class of the overall object, so it has access + # to the known BaseAastra functions. However, hack it like this + # so $this->outer is a pointer to the outer class + ## + var $outer; + + function __construct($outer, $url) { + $this->outer = $outer; + parent::__construct($url); + } + + ## + # The manager() function takes the name of the database list + # the + function manager($list, $showval, $selecturl) { + $this->data = array(); + $l = $this->outer->asm->database_show($list); + if ($showval) { + asort($l); + } else { + $l = array_keys($l); + sort($l); + $l = array_flip($l); + } + foreach($l as $k => $v) { + $a = array(); + $kk = preg_replace('/\/'.$list.'\//', '', $k); + if ($showval) { + $a[] = $v." ".$kk; + } else { + $a[] = $kk; + } + $a[] = $selecturl.$kk; + $this->data[] = $a; + } + $this->outer->displayObject($this); + $this->build(); + } +} +?> |