Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Sunday, September 9, 2007

Squirrelmail with OpenLDAP Addressbook

How Squirrelmail access LDAP server addressbook? In this case you have OpenLDAP server but not an Active Directory !

  • First you must have OpenLDAP service installed on your Linux Box. You can get it free from http://www.openldap.org/software/download/
  • Your PHP must be compiled include LDAP component. You just add --with-ldap when compiling PHP from source.
  • Configure it and specify the OU schema and Addressbook schema in LDIF format.

Please find the steps below:


[/etc/openldap/slapd.conf]
#### SECURITY SETTING ###
disallow bind_anon

#######################################################################
# BDB database definitions
#######################################################################

database bdb
suffix "dc=mycompany,dc=com"
rootdn "dc=mycompany,dc=com"
rootpw {SSHA}UWPj+&**%$^*(7987897*&%*^&*^
directory /var/openldap-data
index objectClass eq


[Addressbook OU]
dn: ou=addressbook,dc=mycompany,dc=com
objectClass: top
objectClass: organizationalUnit
ou: addressbook
userPassword: {SHA}7lUIYUIYKJHKYIYtTkXU=



[Addressbook LDIF]
dn: cn=My Name (myname@mycompany.com),ou=addressbook,dc=mycompany,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: My Name (myname@mycompany.com)
givenName: My Name
sn: My Name
mail: myname@mycompany.com
physicalDeliveryOfficeName: G.Kwarnas
postalAddress: G.Kwarnas
o: mycompany
l: -
ou: addressbook
st: -
postalCode: 10110
telephoneNumber: 1696
facsimileTelephoneNumber: +62-21
pager: +62-21
mobile: +62-21
homePhone: +62-21


How to load LDIF data into OpenLDAP server?
From the Linux shell please type the following command (example the file is "addressbook-2.ldif.txt") :

shell# ldapadd -x -v -c -D "dc=mycompany,dc=com" -W < addressbook-2.ldif.txt

Now is the time to configure Squirrelmail config file. Please add the following script to link your webmail with OpenLDAP server:

[Squirrelmail config.php]
$ldap_server[0] = array(
'host' => '10.80.123.203',
'base' => 'ou=addressbook,dc=mycompany,dc=com',
'name' => 'LDAP: Addressbook Global',
'binddn' => 'ou=addressbook,dc=mycompany,dc=com',
'bindpw' => 'mycompany',
'filter' => '(objectclass=*)',
'protocol' => 3,
'limit_scope' => false,
'listing' => true,
'search_tree' => true,
'starttls' => false
);


Yes! Now your webmail connected with OpenLDAP addressbook.

Tuesday, August 21, 2007

Create Drupal Module

Drupal I think is the best CMS to develop a custom applications. Drupal's engine gives you more than you expected. The API and library will reduce your time to develop applications and gears up your business. This below is example to building modules on drupal engine.

Drupal modules at least need 3 files :

  • yourmodule.info
    Contains module descriptions
  • yourmodule.install
    Contains module database structure (depend on you need database or not)
  • yourmodule.module
    The core of your program. Functions and algorithm write down here.
For example your PATH for drupal is :
/usr/local/apache/htdocs/drupal

In this case, your module name is 'phonedir', so ...your own modules should be :
/usr/local/apache/htdocs/drupal/sites/all/modules/phonedir
All of your module's files must be prefix 'phonedir'.

Your drupal configuration file must be placed at:
/usr/local/apache/htdocs/drupal/sites/default/settings.php

Please edit settings.php to add MySQL connection to the another database:

Origin:
$db_url = 'mysql://drupal:passwd_drupal_db@localhost/drupal';
$db_prefix = '';

To :

## Drupal's db
$db_url['default'] = 'mysql://drupal:passwd_drupal_db@localhost/drupal';

## phonedir's db
$db_url['phonedir'] = 'mysql://phonedir:kunamjaya@localhost/phonedir';
$db_prefix = '';



--------------------------------------------
Run the shell scripts:
============================
# mkdir -p /usr/local/apache/htdocs/drupal/sites/all/modules/phonedir
# cd /usr/local/apache/htdocs/drupal/sites/all/modules/phonedir
Create files : phonedir.info, phonedir.install, phonedir.module, phonedir.mysql
# touch phonedir.info
# touch phonedir.install
# touch phonedir.module
# touch phonedir.mysql
phonedir.info
; $Id$
name = Phonedir
description = Phone Directory
package = PEP
project = "drupal"
version = "5.x-1.0"

phonedir.install
<?
// $Id: phonedir.install,v MDGTI PEP 2007/08/01 13:44:08 drumm Exp $

##########################################
# Konang Supian #
# konangsupian@gmail.com #
# 02 Agustus 2007 #
##########################################

/*
Jalankan perintah shell sbb:
============================
mysql -u root -p -e "create database phonedir"
mysql -u root -p phonedir < phonedir.mysql
echo "\$db_url['phonedir'] = 'mysql://phonedir:kunamjaya@localhost/phonedir';" >> ../../../default/settings.php

*/
###################################################
/*

Tambahkan baris berikut (silakan disesuaikan dengan login password MySQL) di file :
/path/to/drupal/sites/default/settings.php

$db_url['default'] = 'mysql://drupal:kunamjaya@localhost/drupal';
$db_url['helpdesk'] = 'mysql://helpdesk:kunamjaya@localhost/helpdesk';
$db_url['phonedir'] = 'mysql://phonedir:kunamjaya@localhost/phonedir';

*/

function phonedir_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
//db_query("");
break;
}
}

function phonedir_uninstall() {
db_query('DROP TABLE {belomperlu}');
}





phonedir.mysql



/*
Akses command dibawah ini untuk create database dan grant bila belum ada:
#########################################################################
*/

/*
use mysql;
CREATE DATABASE phonedir;
*/

GRANT USAGE ON phonedir.* TO phonedir@localhost;
GRANT ALL ON phonedir.* to phonedir@localhost identified by 'kunamjaya';
flush privileges;

/*
##########################################################################
*/

USE phonedir;

create table ext (
ext_id int auto_increment,
ext_name varchar(40),
ext_jobdesc varchar(30),
ext_div tinyint(3) unsigned,
ext_ext varchar(5),
ext_fax varchar(15),
ext_phone varchar(15),
ext_floor varchar(10),
ext_mail varchar(30),
ext_company tinyint(3) unsigned,
ext_region tinyint(3) unsigned,
PRIMARY KEY (`ext_id`)
) ENGINE=MyISAM;

create table region (
reg_id int auto_increment,
reg_name varchar(30) not null,
reg_status tinyint(3) unsigned default 1,
PRIMARY KEY (`reg_id`),
UNIQUE KEY `reg_name`(`reg_name`)
)ENGINE=MyISAM;

create table prsh (
prsh_id int auto_increment,
prsh_name varchar(30) not null,
prsh_status tinyint(3) unsigned default 1,
PRIMARY KEY (`prsh_id`),
UNIQUE KEY `prsh_name`(`prsh_name`)
)ENGINE=MyISAM;

create table divs (
divs_id int auto_increment,
divs_name varchar(30) not null,
divs_status tinyint(3) unsigned default 1,
PRIMARY KEY (`divs_id`),
UNIQUE KEY `divs_name`(`divs_name`)
)ENGINE=MyISAM;

create table fl (
fl_id int auto_increment,
fl_name varchar(3) not null,
fl_status tinyint(3) unsigned default 1,
PRIMARY KEY (`fl_id`),
UNIQUE KEY `fl_name`(`fl_name`)
)ENGINE=MyISAM;


/*
Dumping data
*/

INSERT INTO `divs` (`divs_id`, `divs_name`, `divs_status`) VALUES (1, 'Kwarnas', 1);
INSERT INTO `divs` (`divs_id`, `divs_name`, `divs_status`) VALUES (2, 'SC', 1);
INSERT INTO `divs` (`divs_id`, `divs_name`, `divs_status`) VALUES (3, 'Keuangan', 1);
INSERT INTO `divs` (`divs_id`, `divs_name`, `divs_status`) VALUES (4, 'Dir Hulu', 1);
INSERT INTO `divs` (`divs_id`, `divs_name`, `divs_status`) VALUES (5, 'PWP', 1);

INSERT INTO `ext` (`ext_name`, `ext_jobdesc`, `ext_div`, `ext_ext`, `ext_fax`, `ext_mail`, `ext_phone`, `ext_floor`) VALUES ('Security lt G', 'Security lt G', '1', '1332', '', '', '', 'G');
INSERT INTO `ext` (`ext_name`, `ext_jobdesc`, `ext_div`, `ext_ext`, `ext_fax`, `ext_mail`, `ext_phone`, `ext_floor`) VALUES ('Pos Depan', 'Pos Depan', '1', '1964', '', '', '', 'G');
INSERT INTO `ext` (`ext_name`, `ext_jobdesc`, `ext_div`, `ext_ext`, `ext_fax`, `ext_mail`, `ext_phone`, `ext_floor`) VALUES ('Storing Listrik', 'Storing Listrik', '1', '1369', ' ', '', '', 'G');
INSERT INTO `ext` (`ext_name`, `ext_jobdesc`, `ext_div`, `ext_ext`, `ext_fax`, `ext_mail`, `ext_phone`, `ext_floor`) VALUES ('Storing AC', 'Storing AC', '1', '1965', '', '', '', 'G');
INSERT INTO `ext` (`ext_name`, `ext_jobdesc`, `ext_div`, `ext_ext`, `ext_fax`, `ext_mail`, `ext_phone`, `ext_floor`) VALUES ('Rec14ionist lt. G', 'Rec14ionist lt. G', '1', '1444', '', '', '', 'G');


INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (1, 'B3', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (2, 'B2', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (3, 'B1', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (4, 'G', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (5, '1', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (6, '2', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (7, '3', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (8, '4', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (9, '5', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (10, '6', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (11, '7', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (12, '8', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (13, '9', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (14, '10', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (15, '11', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (16, '12', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (17, '13', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (18, '14', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (19, '15', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (20, '16', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (21, '17', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (22, '18', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (23, '19', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (24, '21', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (25, '22', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (26, '23', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (27, '24', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (28, '25', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (29, '26', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (30, '27', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (31, '28', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (32, '29', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (33, '30', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (34, '31', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (35, '32', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (36, '33', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (37, '34', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (38, '35', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (39, '36', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (40, '37', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (41, '38', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (42, '39', 1);
INSERT INTO `fl` (`fl_id`, `fl_name`, `fl_status`) VALUES (43, '40', 1);


INSERT INTO `prsh` (`prsh_id`, `prsh_name`, `prsh_status`) VALUES (1, 'MYCOMPANY', 1);
INSERT INTO `prsh` (`prsh_id`, `prsh_name`, `prsh_status`) VALUES (2, 'MYCOMPANY PERSERO', 1);
INSERT INTO `prsh` (`prsh_id`, `prsh_name`, `prsh_status`) VALUES (3, 'PERTAGAS', 1);
INSERT INTO `prsh` (`prsh_id`, `prsh_name`, `prsh_status`) VALUES (4, 'MYCOMPANY PELUMAS', 1);
INSERT INTO `prsh` (`prsh_id`, `prsh_name`, `prsh_status`) VALUES (5, 'REKANAN', 1);


INSERT INTO `region` (`reg_id`, `reg_name`, `reg_status`) VALUES (1, 'Pusat', 1);
INSERT INTO `region` (`reg_id`, `reg_name`, `reg_status`) VALUES (2, 'Sumatera', 1);
INSERT INTO `region` (`reg_id`, `reg_name`, `reg_status`) VALUES (3, 'Jawa', 1);
INSERT INTO `region` (`reg_id`, `reg_name`, `reg_status`) VALUES (4, 'KTI', 1);
INSERT INTO `region` (`reg_id`, `reg_name`, `reg_status`) VALUES (5, 'MYCOMPANY Pusat', 1);




phonedir.module

<?
##########################################
# Konang Supian #
# konangsupian@gmail.com #
# 02 Agustus 2007 #
##########################################

function phonedir_help($section='') {
$output = '';
switch ($section) {
case "admin/help#phonedir":
$output = '<p>'. t("Test buat module"). '</p>';
break;
}
return $output;
}

/*function phonedir_perm() {
return array('PT MYCOMPANY phonedir permission');
}*/

function phonedir_block($op='list', $delta=0) {
if ($op == "list") {
$block[0]["info"] = t("Phonedir");
return $block;
} else if ($op == 'view') {
$block_content = l('Phone Directory', 'phonedir/show') . '<br />';
if ($block_content == '') {
return;
}
$block['subject'] = 'Phonedir';
$block['content'] = $block_content;
return $block;
}
}

/*function phonedir_admin() {
$form['phonedir_maxdisp'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of links'),
'#default_value' => variable_get('phonedir_maxdisp', 3),
'#size' => 2,
'#maxlength' => 2,
'#description' => t("The maximum number of links to display in the block.")
);
return system_settings_form($form);
}*/

function phonedir_menu() {
$items = array();
/*$items[] = array(
'path' => 'admin/settings/phonedir',
'title' => t('Phonedir module settings'),
'description' => t('Description of your phonedir settings control'),
'callback' => 'drupal_get_form',
'callback arguments' => 'phonedir_admin',
'access' => user_access('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);*/
############ PARENT #########
$items[] = array(
'path' => 'phonedir',
'title' => t('Phone Directory'),
'callback' => 'phonedir_load_search',
'access' => user_access('access phonedir content'),
'type' => MENU_NORMAL_ITEM,
);
########### CHILD ##########
$items[] = array(
'path' => 'phonedir/new',
'title' => t('New Entry'),
'callback' => 'phonedir_load_insert',
'access' => user_access('access phonedir content'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'phonedir/list',
'title' => t('Search'),
'callback' => 'phonedir_load_search',
'access' => user_access('access phonedir content'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'phonedir/show',
'title' => t('Pencarian'),
'callback' => 'phonedir_load_search',
'access' => user_access('content'),
'type' => MENU_HIDDEN,
);
$items[] = array(
'path' => 'phonedir/profile',
'title' => t('Profile'),
'callback' => 'phonedir_load_profile',
'access' => user_access('content'),
'type' => MENU_HIDDEN,
);

return $items;
}



############ GLOBAL FUNCTIONS ##############

function phonedir_sql_array($query,$key,$key_index=null) {
db_set_active('phonedir');
$queryResult = db_query($query);
while ($links = db_fetch_object($queryResult)) {
if ($key_index!=null) {
$myarray[$links->$key_index] = $links -> $key;
} else {
$myarray[] = $links -> $key;
}
}
db_set_active('default');
return $myarray;
}

function phonedir_printfield($table,$field,$field_,$syarat) {
db_set_active('phonedir');
$query_ = "select ".$field." from ".$table." where ".$field_."='".$syarat."'";
$admin_ = mysql_query($query_);
$row_ = mysql_fetch_array($admin_);
if (!$admin_) {
echo mysql_error();
}
db_set_active('default');
return $row_[0];
}

function phonedir_list_data($caption,$table,$field,$syarat,$start,$script,$isnew,$href,$target,$q) {
$content = '';
if ($start > 0) { $anyar = $isnew;}
$show_per_page = 30;
$list_page = 11;
if ($start < $show_per_page) $start = 0;
if ($syarat != "") {
$mynewquery = "select ".$field." from ".$table." ".$syarat." limit $start,$show_per_page";
$mynewquery1 = "select count(*) from ".$table." ".$syarat;
} else {
$mynewquery = "select ".$field." from ".$table." limit $start,$show_per_page";
$mynewquery1 = "select count(*) from ".$table;
}
$result = mysql_query($mynewquery);

#print $mynewquery;

if (!$result) {
print mysql_error();
}
$hasil = mysql_query($mynewquery1);
$hasil = mysql_fetch_row($hasil);
$hasil = $hasil[0];

$content .= '
<table id="tbl-phonedir" width="100%" border="1" cellspacing="1" cellpadding="2">
<tr class="thead"><td colspan="'.mysql_num_fields($result).'">
&nbsp;<b>'.$caption.'</b> <i>('.$hasil.')</i>
</td>
</tr>
<tr class="tcol">';
for ($i = 0; $i< mysql_num_fields($result); $i++) {
$head = mysql_field_name( $result,$i);
$content .= "<td><b>$head</b></td>";
}
$content .= "</tr>";
$myrow = 1;
for ($i=0; $i < $show_per_page; $i++) {
if ($result <> 0 ) { $row_array = mysql_fetch_row($result);}
if ($row_array=="") { break; }
if ($i % 2 == 0) {
$warna = "teven";
} else {
$warna = "todd";
}
$content .= "\r\n<tr class=\"$warna\">\r\n";
for ($j=0; $j<mysql_num_fields($result); $j++) {
if (eregi("accessed",mysql_field_name($result,$j))) {
$row_array[$j] = tanggalan($row_array[$j]);
}
if ($j==0) {
$content .= "<td align=\"center\">";
$content .= ($myrow+$start);
} else {
$content .= "<td align=\"left\">";
if ($href==$j) {
$content .= '<a href="'.$target.'&id='.$row_array[$q].'">'.$row_array[$j].'</a>';
} else {
if (!eregi("STATUS",mysql_field_name($result,$j))) {
$tulis = eregi_replace("\n","<br>",$row_array[$j]);
$content .= $tulis;
}
}
}
$content .= "</td>";
}
$myrow++;
$content .= "</tr>";
}
$content .= phonedir_idx_page($hasil, $show_per_page, $list_page, $start, $script, $anyar, mysql_num_fields($result) , "#dddddd");
$content .= "
</table>";

return $content;
}


function phonedir_idx_page($hasil, $show_per_page, $list_page, $start, $url, $isnew, $colspan, $warna) {
$content = '';
$content .= '
<tr class="tfoot"><td colspan="'.$colspan.'">
';

if ($hasil > 0) {
$counter = 1;
$tmp_start = $start;
$start = 0;
$first = 0;
$last = floor($hasil/$show_per_page)*$show_per_page;
$next = $tmp_start+$show_per_page;
$pembagi = ($next-($show_per_page * ($list_page-1) ));
$pembagi = floor($pembagi / $show_per_page);
if ($pembagi>0) {
$prev=$next-(2*$show_per_page);
$content .= "<a href='$url&start=$first'>&laquo; first</a> <a href='$url&start=$prev'>prev</a> ";
}
if ($hasil <> 0 ) { $content .= "";}
for ($i=0; $i < $hasil; $i++) {
if (($i % $show_per_page) == 0) {
if (($counter % $list_page)==0) {
if ($next>$last) {$next=$last;}
$content .= " <a href='$url&start=$next'>next</a>";
$content .= " <a href='$url&start=$last'>last &raquo;</a>";
break;
}
if ($isnew=="") {
if ($counter>1) {
if ($pembagi>0) {
$list=$counter+$pembagi;
$urllist=($list-1)*$show_per_page;
$content .= "&nbsp;<a href='$url&start=$urllist'>$list</a>&nbsp;";

} else {
$content .= "&nbsp;<a href='$url&start=$start'>$counter</a>&nbsp;";
}
} else {
if ($pembagi>0) {
$list=$counter+$pembagi;
$content .= $list . "&nbsp;";
} else {
$content .= $counter . "&nbsp;";
}
}

} else {
if ($i == $tmp_start ) {
if ($pembagi>0) {
$list=$counter+$pembagi;
$content .= $list . "&nbsp;";
} else {
$content .= $counter . "&nbsp;";
}
} else {
if ($pembagi>0) {
$list=$counter+$pembagi;
$urllist=($list-1)*$show_per_page;
$content .= "&nbsp;<a href='$url&start=$urllist'>$list</a>&nbsp;";
} else {
$content .= "&nbsp;<a href='$url&start=$start'>$counter</a>&nbsp;";
}
}
}
$start= $start + $show_per_page;
$counter = $counter + 1;
}
}
}
$content .= '
</td>
';
return $content;
}


############### INSERT DATA ################

function phonedir_insert_form() {
$divisi_ = phonedir_sql_array('select * from divs','divs_name','divs_id');
$pt_ = phonedir_sql_array('select * from prsh','prsh_name','prsh_id');
$region_ = phonedir_sql_array('select * from region','reg_name','reg_id');
$lantai_ = phonedir_sql_array('select * from fl','fl_name','fl_name');

//$options = array('1' => t('Enabled'), '0' => t('Disabled'));
$form['user'] = array(
'#type' => 'fieldset',
'#title' => t('Data Ekstensi Telepon'),
'#tree' => TRUE,
);
$form['user']['name'] = array(
'#type' => 'textfield',
'#title' => t('Nama Karyawan'),
'#size' => 30,
'#maxlength' => 64,
);
$form['user']['ext'] = array(
'#type' => 'textfield',
'#title' => t('Ext'),
'#size' => 5,
'#maxlength' => 5,
);
$form['user']['jobdesc'] = array(
'#type' => 'textfield',
'#title' => t('Jabatan'),
'#size' => 30,
'#maxlength' => 30,
);
$form['user']['mail'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#size' => 30,
'#maxlength' => 30,
);
$form['user']['fax'] = array(
'#type' => 'textfield',
'#title' => t('Fax'),
'#size' => 15,
'#maxlength' => 15,
);
$form['user']['phone'] = array(
'#type' => 'textfield',
'#title' => t('Telepon'),
'#size' => 15,
'#maxlength' => 15,
);
$form['user']['floor'] = array(
'#type' => 'select',
'#title' => t('Lantai'),
'#options' => $lantai_,
);
$form['user']['div'] = array(
'#type' => 'select',
'#title' => t('Divisi'),
'#options' => $divisi_,
);
$form['user']['company'] = array(
'#type' => 'select',
'#title' => t('Nama Perusahaan'),
'#options' => $pt_,
);
$form['user']['region'] = array(
'#type' => 'select',
'#title' => t('Region'),
'#options' => $region_,
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}

function phonedir_load_insert() {
return drupal_get_form('phonedir_insert_form');
}

function phonedir_insert_form_validate($form_id, $form_values) {
if ($form_values['user']['name'] == '') {
form_set_error('', t('Nama karyawan tidak boleh kosong!'));
}
if ($form_values['user']['ext'] == '') {
form_set_error('', t('Ekstension telpon tidak boleh kosong!'));
}
}

function phonedir_insert_form_submit($form_id, $form_values) {
db_set_active('phonedir');
$result = db_query("INSERT INTO ext (ext_name,ext_jobdesc,ext_div,ext_ext,ext_fax,ext_floor,ext_mail,ext_company,ext_region)
VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')",
$form_values['user']['name'], $form_values['user']['jobdesc'], $form_values['user']['div'],$form_values['user']['ext'],$form_values['user']['fax'],$form_values['user']['floor'],$form_values['user']['mail'],$form_values['user']['company'],$form_values['user']['region']);
if (!$result) {
drupal_set_message(t('Bermasalah dalam memasukkan data : DUPLIKASI'));
} else {
drupal_set_message(t('Data ekstension telepon karyawan telah berhasil disimpan.'));
}
db_set_active('default');
}


############# SEARCH ##############

function phonedir_search_form() {
$divs__ = array("0"=>'ALL');
$divs___ = phonedir_sql_array('select * from divs','divs_name','divs_id');
$divs_ = array_merge($divs__,$divs___); ## pulldown content
$search = $_GET['search'];
$divs = $_GET['divs']; ## current divs from GET
if (!$qq) $qq = $_GET['qq'];
if (!$start) $start = $_GET['start'];

if ($divs) {
$caption_divs = strtoupper(phonedir_printfield("divs","divs_name","divs_id",$divs));
}

$form['user'] = array(
'#type' => 'fieldset',
'#title' => t('Cari Ekstensi Telepon'),
'#tree' => TRUE,
);
$form['user']['qq'] = array(
'#type' => 'textfield',
'#title' => t('Nama Karyawan'),
'#default_value' => $qq,
'#size' => 30,
'#maxlength' => 64,
'#description' => 'Boleh nama depan, nama tengah atau belakang.',
);
$form['user']['fungsi'] = array(
'#type' => 'select',
'#title' => t('Nama Fungsi'),
'#options' => $divs_,
);

$form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
$form['#redirect']=FALSE;

$form['spacer'] = array(
'#type' => 'item',
'#size' => 0,
'#maxlength' => 0,
'#value' => t('')
);

$form ['hasil'] = array(
'#type' => 'fieldset',
'#title' => 'Hasil Pencarian1',
'#tree' => TRUE,
);

if ($divs) {
$add_query = ' and ext_div='.$divs;
}

if ($qq && $start>=0) {
db_set_active('phonedir');
$content = phonedir_list_data("EKSTENSI TELEPON ".$caption_divs,"ext",
"ext_id as NO,ext_name as NAMA,ext_ext as EXT,ext_floor as LT,divs_name as FUNGSI, ext_jobdesc as JABATAN, ext_phone as TLP", "left join divs on (ext_div=divs_id) left join region on (ext_region=reg_id) left join prsh on (ext_company=prsh_id) where ext_name like '%".$qq."%'".$add_query,
$start,"?q=phonedir/show&qq=".$qq."&divs=".$divs,$start,1,"profile",0);
db_set_active('default');
} elseif (!$qq && $start>0) {
db_set_active('phonedir');
$content = phonedir_list_data("EKSTENSI TELEPON ".$caption_divs,"ext",
"ext_id as NO,ext_name as NAMA,ext_ext as EXT,ext_floor as LT,divs_name as FUNGSI,ext_jobdesc as JABATAN, ext_phone as TLP", "left join divs on (ext_div=divs_id) left join region on (ext_region=reg_id) left join prsh on (ext_company=prsh_id) where ext_name like '%".$qq."%'".$add_query,
$start,"?q=phonedir/show&qq=".$qq."&divs=".$divs,$start,1,"profile",0);
db_set_active('default');
} elseif (!$qq && $start=='0') {
if ($search) {
db_set_active('phonedir');
$content = phonedir_list_data("EKSTENSI TELEPON ".$caption_divs,"ext",
"ext_id as NO,ext_name as NAMA,ext_ext as EXT,ext_floor as LT,divs_name as FUNGSI,ext_jobdesc as JABATAN, ext_phone as TLP", "left join divs on (ext_div=divs_id) left join region on (ext_region=reg_id) left join prsh on (ext_company=prsh_id) where 1".$add_query,
$start,"?q=phonedir/show&qq=".$qq."&divs=".$divs,$start,1,"profile",0);
db_set_active('default');
} elseif (!$search) {
header("Location: ?q=phonedir/show&qq=$qq&divs=$divs&start=0&search=Search");
}
}

$form ['hasil']['test'] = array(
'#type' => 'item',
'#size' => 0,
'#maxlength' => 0,
'#description' => $content,
);

return $form;
}

function phonedir_load_search() {
return drupal_get_form('phonedir_search_form');
}

function phonedir_search_form_submit($form_id, $form_values) {
db_set_active('phonedir');
$qq = eregi_replace("'","`",$form_values['user']['qq']);
$divs = $form_values['user']['fungsi'];
$search = $form_values['submit'];
header("Location: ?q=phonedir/show&qq=$qq&divs=$divs&start=0&search=$search");
db_set_active('default');
}



############## Profile ###############

function phonedir_profile_form() {
$divs__ = array("0"=>'ALL');
$divs___ = phonedir_sql_array('select * from divs','divs_name','divs_id');
$divs_ = array_merge($divs__,$divs___); ## pulldown content
$search = $_GET['search'];
$divs = $_GET['divs'];
$id = $_GET['id']; # profile's id
if (!$id) $id = $_GET['id'];

db_set_active('phonedir');
$query = "select ext_id as NO,ext_name as NAMA,ext_ext as EXT,ext_floor as LT,divs_name as FUNGSI,ext_jobdesc as JABATAN, ext_phone as TLP, prsh_name as PRSH, reg_name as REGION from ext left join divs on (ext_div=divs_id) left join region on (ext_region=reg_id) left join prsh on (ext_company=prsh_id) where ext_id=".$id;
$result = mysql_query($query);
if ($result)
$row_array = mysql_fetch_array($result);
db_set_active('default');

if ($divs) {
$caption_divs = strtoupper(phonedir_printfield("divs","divs_name","divs_id",$divs));
}

$form['pro'] = array(
'#type' => 'fieldset',
'#title' => t('Cari Ekstensi Telepon'),
'#tree' => TRUE,
);
$form['pro']['qq'] = array(
'#type' => 'textfield',
'#title' => t('Nama Karyawan'),
'#default_value' => $row_array["NAMA"],
'#size' => 30,
'#maxlength' => 64,
'#description' => 'Boleh nama depan, nama tengah atau belakang.',
);
$form['pro']['fungsi'] = array(
'#type' => 'select',
'#title' => t('Nama Fungsi'),
'#options' => $divs_,
);

$form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
$form['#redirect']=FALSE;

$form['spacer'] = array(
'#type' => 'item',
'#size' => 0,
'#maxlength' => 0,
'#value' => t('')
);

$form ['mypro'] = array(
'#type' => 'fieldset',
'#title' => 'Lihat Profile',
'#tree' => TRUE,
);

$content = "<h3><font color='#444444'><label for='edit-pro-qq'>";
$content .= $row_array["NAMA"] . "<br />";
$content .= $row_array["JABATAN"] . "<br />";
$content .= $row_array["FUNGSI"] . "<br />";
$content .= $row_array["PRSH"] . " " . $row_array["REGION"];
$content .= "Ext : " . $row_array["EXT"] . "<br />";
$content .= "Lantai : " . $row_array["LT"] . "<br />";
$content .= "Telepon : " . $row_array["TLP"] . "<br />";
$content .= "</label></font></h3>";

$form ['mypro']['view'] = array(
'#type' => 'item',
'#size' => 0,
'#maxlength' => 0,
'#description' => $content,
);

return $form;
}

function phonedir_load_profile() {
return drupal_get_form('phonedir_profile_form');
}

function phonedir_profile_form_submit($form_id, $form_values) {
db_set_active('phonedir');
$qq = eregi_replace("'","`",$form_values['pro']['qq']);
$divs = $form_values['pro']['fungsi'];
$search = $form_values['submit'];
header("Location: ?q=phonedir/show&qq=$qq&divs=$divs&start=0&search=$search");
db_set_active('default');
}

db_set_active('default');
?>



Gammu SMS Gateway

Source:
Please download : http://www.gammu.org/

Dependencies
Driver USB "usbserial pl2303"

Please check /var/log/messages when your modem plugged:
May 2 07:43:08 localhost kernel: usb 4-2: new full speed USB device using
uhci_hcd and address 3
May 2 07:43:08 localhost kernel: usb 4-2: configuration #1 chosen from 1
choice
May 2 07:43:08 localhost kernel: pl2303 4-2:1.0: pl2303 converter detected
May 2 07:43:08 localhost kernel: usb 4-2: pl2303 converter now attached
to ttyUSB0

If you see your LOG contain text above so the driver pl2303 has been load and ready to use.
If something problem and you can't find anything in your LOG please try :


# /sbin/modprobe -l grep serial
# /sbin/lspci grep USB
# /sbin/lsmod grep usb


Configure GAMMU
# tar -zxvf gammu-1.10.3.tar.gz
# make
# make install

Please read README first for details information. Please create MySQL account, create GRANT and load gammu mysql structure to gammu's mysql user.


Startup file for GAMMU

startgammu.sh
#!/bin/sh
export LANG=en_US.UTF-8
killall -9 gammu
/usr/local/bin/gammu --smsd MYSQL /etc/smsdrc &
echo 'Gammu SMS GTW Starting ...' /usr/local/bin/gammu --sendsmsdsms TEXT
081112223333 MYSQL /etc/smsdrc

Exec Path:
/usr/local/bin/gammu

Config File:
# /etc/gammurc
[gammu]
port = /dev/ttyUSB0
connection = at115200
logfile = /var/log/gammulog
logformat = textall
startinfo = yes
gammucoding = utf8

# /etc/smsdrc
[smsd]
PIN = 1234
logfile = /var/log/smsdlog
commtimeout = 1
sendtimeout = 10
deliveryreport = log
phoneid = PEP-SMS-GTW
# MYSQL
user = smsd
password = kunamjaya
pc = localhost
database = smsd

Startup:
/usr/local/bin/startgammu.sh

Links:
http://linux2.arinet.org/index.php?option=com_content&task=view&id=121&Itemid=2
http://aswandi.or.id/2006/09/28/sms-gateway-di-windows/#comments
http://wammu.eu/



send.php

<?
### konangsupian@gmail.com ###
### 01 Mei 2007 ###

$conn = mysql_connect("10.10.123.252","gammu","kunamjaya");
if (!$conn) {
echo mysql_error();
}
mysql_select_db("gammu");

function hexsms($kata) {
$tmp = "";
for ($i=0; $i<strlen($kata);$i++) {
$tmp_ = bin2hex($kata[$i]);
$tmp .= str_pad($tmp_, 4, "00", STR_PAD_LEFT);
}
return strtoupper($tmp);
}

function aman($myvar) {
return eregi_replace("'","`",$myvar);
}

$waktu = date("Y-m-d G:i:s");
#$Text=hexsms(aman($_POST["sms"]));
$DestinationNumber=aman($_POST["to"]);
$Coding="Default_No_Compression";
$UDH="";
$Class="-1";
$TextDecoded=aman($_POST["sms"]);
$MultiPart="false";
$RelativeValidity="255";
$SenderID="";
$SendingTimeOut="0000-00-00 00:00:00";
$DeliveryReport="default";
$CreatorID="Gammu 1.10.3";

$result = mysql_query("insert into outbox (UpdatedInDB,InsertIntoDB,SendingDateTime,Text,DestinationNumber,Coding,UDH,Class,TextDecoded,MultiPart,RelativeValidity,SenderID,
SendingTimeOut,DeliveryReport,CreatorID)
values
('now()','now()','now()','$Text','$DestinationNumber','$Coding','$UDH','$Class','$TextDecoded','$MultiPart','$RelativeValidity','$SenderID','$SendingTimeOut','$Deli
veryReport','$CreatorID')");

if (!$result) {
print mysql_error();
}

header('Location: index.html');

?>


index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MYCOMPANY - SMS Gateway Interface</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT language="JavaScript">

function rand()
{
randomku = Math.random(1234567890);
strku = String(randomku);
strku = strku.replace('0.0','');
strku = strku.replace('0.','');
return document.form1.code.value = strku;
}

</SCRIPT>
</head>

<body onLoad="JavaScript:rand()">
<br>
<br>
<form action="http://localhost/sms/send.php" method="post" name="form1">
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#000000"><table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr bgcolor="#FF9933">
<td colspan="2" align="left"><font size="2" face="Arial, Helvetica, sans-serif"><strong>::: MYCOMPANY - SMS GTW
</strong></font></td>
</tr>
<tr align="left" valign="middle" bgcolor="#FFFFFF">
<td width="80" nowrap><strong><font size="2" face="Arial, Helvetica, sans-serif">To</font></strong></td>
<td width="100%"><font size="2" face="Arial, Helvetica, sans-serif">
<input name="to" type="text" value="0812">
</font></td>
</tr>

<tr align="left" valign="middle" bgcolor="#FFFFFF">
<td width="80" nowrap><strong><font size="2" face="Arial, Helvetica, sans-serif">ID</font></strong></td>
<td width="100%"> <font size="2" face="Arial, Helvetica, sans-serif">
<input name="idserver" type="text" value="PEP-SMS-GTW" readonly style="border=0;">
</font></td>
</tr>
<tr align="left" valign="middle" bgcolor="#FFFFFF">
<td width="80" nowrap><strong><font size="2" face="Arial, Helvetica, sans-serif">Code</font></strong></td>
<td width="100%"><font size="2" face="Arial, Helvetica, sans-serif">
<input type="text" name="code" readonly style="border=0;">
</font></td>
</tr>
<tr align="left" valign="middle" bgcolor="#FFFFFF">
<td width="80" nowrap><font size="2" face="Arial, Helvetica, sans-serif"><strong>Length</strong></font></td>
<td width="100%"><font size="2" face="Arial, Helvetica, sans-serif">
<input name="len" type="text" size="3" maxlength="3" readonly style="border=0; font-family:; color=#ff0000;">
</font></td>
</tr>
<tr valign="top" bgcolor="#FFFFFF">
<td width="80" nowrap><strong><font size="2" face="Arial, Helvetica, sans-serif">SMS</font></strong></td>
<td width="100%"><font size="2" face="Arial, Helvetica, sans-serif">
<textarea name="sms" cols="40" rows="5" id="sms" onKeyUp="form1.len.value=this.value.length"></textarea>
</font></td>
</tr>
<tr bgcolor="#dddddd">
<td width="80" nowrap><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td width="100%"><font size="2" face="Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Submit">
</font></td>
</tr>

</table></td>
</tr>
</table>
</form>
</body>
</html>


Oracle Instant Client for PHP & Linux

Service
instantclient-basic-linux32-10.2.0.2-20060331
instantclient-sdk-linux32-10.2.0.2-20060331


Download
http://www.oracle.com/technology/software/tech/oci/instantclient/index.htm
http://www.oracle.com/technology/software/htdocs/client_lic.html?url=http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.h

http://download.oracle.com/otn/linux/instantclient/10202/instantclient-basic-linux32-10.2.0.2-20060331.zip
http://download.oracle.com/otn/linux/instantclient/10202/instantclient-sdk-linux32-10.2.0.2-20060331.zip


Links
http://us3.php.net/oci8


Configure Oracle Client
Install Oracle instant client

# mkdir -p /usr/lib/oracle/10.2.0.2/client
# unzip -jd /usr/lib/oracle/10.2.0.2/client \
instantclient-basic-linux-x86-32-10.2.0.2-20060331.zip
# mkdir -p /usr/include/oracle/10.2.0.2/client
# unzip -jd /usr/include/oracle/10.2.0.2/client \
instantclient-sdk-linux-x86-32-10.2.0.2-20060331.zip
# ln -s /usr/lib/oracle/10.2.0.2/client/libclntsh.so.10.1 \
/usr/lib/oracle/10.2.0.2/client/libclntsh.so
# cp /usr/include/oracle/10.2.0.2/client/* /usr/lib/oracle/10.2.0.2/client/


Configure Apache
# ./configure --prefix=/usr/local/apache \
--enable-shared=max --enable-module=vhost_alias
Alternate compile to another directory
## ./configure --prefix=/usr/local/apache4 \
--enable-shared=max --enable-module=so \
--enable-module=vhost_alias
## Reconfigure PHP 4.x.x
# ./configure --with-mysql \
--with-ldap \
--with-gettext \
--with-apxs=/usr/sbin/apxs \
--with-oci8-instant-client=/usr/lib/orale/10.2.0.2/client
## Reconfigure PHP 5.x.x
# ./configure --with-mysql=/usr --with-ldap \
--with-gettext --enable-versioning \
--enable-memory-limit --enable-zend-multibyte \
--enable-zip --enable-track-vars \
--with-apxs=/usr/local/apache/bin/apxs \
--with-calendar \
--with-oci8=instantclient,/usr/lib/oracle/10.2.0.2/client
# export LD_LIBRARY_PATH=\
/usr/lib/oracle/10.2.0.2/client:$LD_LIBRARY_PATH
# make
# make install


Please restart apache and test connection with source code below :

### Test your PHP Oracle connection ####

### oci.php ###

<?

define("_USER","ora");

define("_PASSWD","ora");

define("_DB","10.8.8.8/ORA");

$conn = OCILogon(_USER,_PASSWD,_DB) or die(OCIError());


if ($conn){

print "Terkoneksi ke database ". _DB . " sebagai user "
. _USER."<BR>";

echo "CONN=".$conn."<br>";

} else {

exit;

}


$cmdstr = "select * from TB_VENDOR";

$parsed = ociparse($conn, $cmdstr);

ociexecute($parsed);

$nrows = ocifetchstatement($parsed, $results);


echo "<html><head><title>Oracle PHP Test</title></head><body>";

echo "<center><h2>Oracle PHP Test for <i><u>Obsolete</u></i>
Command</h2></center>";

echo "<center><h2>Connecting & Accessing Oracle Database</h2><br>";

echo "<table border=1 cellspacing='0' width='50%'>\n<tr>\n";

echo "<td><b>NAMA PT</b></td>\n<td><b>ALAMAT</b></td>\n</tr>\n";


for ($i = 0; $i < $nrows; $i++ )

{

echo "<tr>\n";

echo "<td>" . $results["NM_VENDOR"][$i] . "</td>";

echo "<td> " . $results["ALAMAT"][$i] . "</td>";

echo "</tr>\n";

}


echo "<tr><td colspan='2'> Number of Rows:
$nrows</td></tr></table>";

echo "<br><em>If you see data, then it works!</em><br></center></body></html>\n";


print "<hr>";

echo "<center><h2>Oracle PHP Test for <i><u>Newest</u></i>
Command</h2></center>";

echo "<center><h2>Connecting & Accessing Oracle Database</h2><br>";


$conn = OCILogon(_USER,_PASSWD,_DB) or die(OCIError());

if (!$conn) {

$e = oci_error();

print htmlentities($e['message']);

exit;

}


$query = 'SELECT * FROM TB_SOLUSI';


$stid = oci_parse($conn, $query);

if (!$stid) {

$e = oci_error($conn);

print htmlentities($e['message']);

exit;

}


$r = oci_execute($stid, OCI_DEFAULT);

if (!$r) {

$e = oci_error($stid);

echo htmlentities($e['message']);

exit;

}


print '<table border="1">';

while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {

print '<tr>';

foreach ($row as $item) {

print '<td>'.($item?htmlentities($item):' ').'</td>';

}

print '</tr>';

}

print '</table>';

echo "<center><br><em>If you see data, then it works!</em><br></center>";

oci_close($conn);



?>

Search Linux Resources