[Added directory search for SIP accounts Adrian Georgescu **20091128195324] hunk ./library/sip_settings.php 60 + var $show_directory = false; hunk ./library/sip_settings.php 556 + if ($this->soapEngines[$this->sip_engine]['show_directory']) { + $this->show_directory = $this->soapEngines[$this->sip_engine]['show_directory']; + } + hunk ./library/sip_settings.php 4638 - dprint("showPhonebook()"); + dprint("showContactsTab()"); + + if ($this->show_directory) { + $chapter=sprintf(_("Global Directory")); + $this->showChapter($chapter); + + print " + + "; + + $this->showSearchDirectory(); hunk ./library/sip_settings.php 4650 - $chapter=sprintf(_("Contacts")); + print " + + + "; + + } + + if ($this->rows) { + // hide local contacts if we found a global contact + return true; + } + + $chapter=sprintf(_("Local Contacts")); hunk ./library/sip_settings.php 4674 - hunk ./library/sip_settings.php 4748 + "; + print _("Name"); + print " hunk ./library/sip_settings.php 4758 + print _('Group'); hunk ./library/sip_settings.php 6544 + function showDirectorySearchForm () { + print " +

+ + + url method=post> + + + + + + +
"; + print _("First Name"); + printf (" ",$_REQUEST['firstname']); + + print _("Last Name"); + + printf (" ",$_REQUEST['lastname']); + + print ""; + print ""; + print "
+ "; + } + + function showSearchDirectory() { + + if (!$this->show_directory) { + return false; + } + + $this->maxrowsperpage=20; + + $this->showDirectorySearchForm(); + + if ($_REQUEST['firstname'] || $_REQUEST['lastname']) { + if ($_REQUEST['firstname'] && strlen($_REQUEST['firstname']) < 3) { + return false; + } + if ($_REQUEST['lastname'] && strlen($_REQUEST['lastname']) < 3) { + return false; + } + + } else { + return false; + } + + $this->next = $_REQUEST['next']; + + // Filter + $filter=array('firstName'=> trim($_REQUEST['firstname']), + 'lastName' => trim($_REQUEST['lastname']) + ); + + // Range + $range=array('start' => intval($this->next), + 'count' => intval($this->maxrowsperpage) + ); + + // Order + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; + + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); + + // Compose query + $Query=array('filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); + + // Insert credetials + $this->SipPort->addHeader($this->SoapAuth); + + // Call function + $result = $this->SipPort->getAccounts($Query); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + return false; + } + + $this->rows = $result->total; + + if (!$this->next) $this->next=0; + + if ($this->rows > $this->maxrowsperpage) { + $maxrows = $this->maxrowsperpage + $this->next; + if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage; + } else { + $maxrows=$this->rows; + } + + if ($this->rows) { + print " +

+ + +
$this->rows contacts found
+

+ + + "; + + print ""; + print ""; + print ""; + print ""; + + print " + + "; + + + $i=0; + + while ($i < $maxrows) { + + if (!$result->accounts[$i]) break; + + $account = $result->accounts[$i]; + + $index=$this->next+$i+1; + + $rr=floor($index/2); + $mod=$index-$rr*2; + + if ($mod ==0) { + $_class='odd'; + } else { + $_class='even'; + } + + $i++; + $sip_account=sprintf("%s@%s",$account->id->username,$account->id->domain); + printf ("", + $_class, + $index, + $account->firstName, + $account->lastName, + $sip_account, + $account->timezone, + $this->PhoneDialURL($sip_account) + ); + } + + print "
"; + print _('Display Name'); + print ""; + print _('SIP Address'); + print ""; + print _('Timezone'); + print ""; + print _('Actions'); + print "
%d%s %s%s%s%s
"; + + $this->showPagination($maxrows); + + return true; + } + } + + function showPagination($maxrows) { + + $url = sprintf("%s&tab=%s&firstname=%s&lastname%s", + $this->url, + $this->tab, + $_REQUEST['firstname'], + $_REQUEST['lastname'] + ); + + print " +

+ + + + + +
+ "; + + if ($this->next != 0 ) { + $show_next=$this->maxrowsperpage-$this->next; + if ($show_next < 0) { + $mod_show_next = $show_next-2*$show_next; + } + if (!$mod_show_next) $mod_show_next=0; + + if ($mod_show_next/$this->maxrowsperpage >= 1) { + printf ("Begin ",$url); + } + + printf ("Previous ",$url,$mod_show_next); + } + + print " + + "; + + if ($this->next + $this->maxrowsperpage < $this->rows) { + $show_next = $this->maxrowsperpage + $this->next; + printf ("Next ",$url,$show_next); + } + + print " +
+ "; + } +