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');
?>



7 comments:

Anonymous said...

e elmu kok ra diamalke....slamet, wis entuk pirang ndollar ?

dax said...

im very much interested in this, is there any chance you could change the comments and codes to english? actually, i understand a bit, but it'll be really great if i can understand your code fully. this is, actually, exactly what i've been looking for. thanks

Anonymous said...

mazkm [url=http://www.milesplit.us/members/Tadalafil/]generic tadalafil 20mg[/url] fkynbsc

Anonymous said...

I would like to exchange links with your site www.blogger.com
Is this possible?

Anonymous said...

With kind regards! call
[url=http://pussy.hqporn.us/][img]http://pics.hqtube.com/gallery/anal_xplosion_sc4_2.jpg[/img][/url] [url=http://japan.hqporn.us/][img]http://pics.hqtube.com/gallery/blame_it_on_daddy_2_sc1_1.jpg[/img][/url] [url=http://japan.hqporn.us/][img]http://pics.hqtube.com/gallery/babysitter_9_sc1_2.jpg[/img][/url] [url=http://www.hqtube.com/?5736000000/][img]http://pics.hqtube.com/gallery/the_awakening_of_keegan_sc3_3.jpg[/img][/url]
A site featuring bi-sexual MMF action [url=http://lesbian.hqporn.us/]depraved porn [/url] , dirty porn [url=http://teen.hqporn.us/]15 minutes free porn [/url] or banned porn [url=http://www.hqtube.com/?5736000000/]swiss porn [/url] , free bbw porn clips [url=http://join.hqtube.com/track/qx4DABkR/]netflix of porn [/url] or hottest porn ever [url=http://tube.hqporn.us/]alladin porn [/url] , donna doll porn [url=http://lesbian.hqporn.us/]ecuadorian porn [/url] and hunter porn [url=http://tube.hqporn.us/]porn bot [/url] or female erotica porn [url=http://gay.hqporn.us/]british porn [/url] , Other celeb sites just have a few nipple slip pictures and maybe a few short nude movie clips. Babylon X is the celebrity mega site. For ten plus years, Babylon X has collected everything from nude celeb pictures and movies to explicit hardcore celebrity action. [url=http://pakeko.createphpbb.com/post123584.html#p123584]free porn pics world [/url] . F Allie Jordan on Brand New Faces new [url=http://roqueblave.info/bitweaver/phpbb/viewtopic.php?p=23229&sid=471e441fa8cc8e0b3cb8336ade3d4044#23229]japanese free porn [/url] . F Reverse Gangbang Vids new [url=http://forum.maksimir.com/viewtopic.php?f=5&t=28395]portable porn [/url] . PREMIUM DVDs [url=http://mservices.cl/foro//viewtopic.php?p=200769#200769]porn hub tube [/url] . Adult Gold Access is the newest offer that actually gives you more bang for your buck, literally. You get access to 6 adult mega sites for the price of one sign up. Really, really worth it. Comics, celebs, big tits, porn stars and so much more. Check it out today. [url=http://cssra.phpbbserver.com/post95580.html#p95580]disney princess porn [/url] , P Her First Lesbian Sex new [url=http://milf.hqporn.us/]hm home made porn [/url] , free porn xnxx [url=http://www.hqtube.com/?5736000000/]the girls next door porn [/url] or brandy c porn [url=http://tube.hqporn.us/]free father daughter porn [/url] , army porn [url=http://granny.hqporn.us/]asian woman free porn [/url] or retro boys porn [url=http://teen.hqporn.us/]free real porn [/url] , jamie james porn star [url=http://pussy.hqporn.us/]illegal gay porn [/url] and rice fever porn [url=http://gay.hqporn.us/]shay hendrix porn [/url] or elephant list free porn [url=http://granny.hqporn.us/]youngest teen porn [/url] , Click here to visit MyFreePaysite, all you need is a valid email and never a credit card! [url=http://www.sophipolis.net/foro//viewtopic.php?p=126556#126556]illegal porn movies [/url] . P Her First Lesbian Sex new [url=http://www.awczurich.org/appiesboard/viewtopic.php?p=112749#112749]free porn thumbnail [/url] . 15 pics of Babes : sienna lets the california sun kiss her perfect big boobs and smooth round butt. [url=http://www.ta-designs.co.uk/streamshackforum/viewtopic.php?p=1308908#1308908]porn guys [/url] . Only the best 18-19 y.o. models! Thousands of teen softcore or hardcore action photos and awesome teen porn videos. [url=http://www.holamor.com/phpBB2/viewtopic.php?p=739098#739098]free xxx adult porn [/url] . Fun times at this pool party when it turns into groupsex cluster fuck. [url=http://huixtepec.com.mx/foros/index.php?topic=113630.new#new]bart and lisa porn [/url] , good day.....

mens erotic stories said...

Pulling his pant over his butt crack Ziggy pointed atthe Death by chocolate cake That one Steffy itlooks scrumptious I wouldnt mind having sex on thatcake. Teela had been firstattracted to the guys eyes while everyone elses had been pools of fear,this guy had been calm, wary, intelligent a possible predator.
mother son sex stories
erotic stories images violent sex
lesbian porn stories
free amateur sex stories
straitjacket bondage stories
Pulling his pant over his butt crack Ziggy pointed atthe Death by chocolate cake That one Steffy itlooks scrumptious I wouldnt mind having sex on thatcake. Teela had been firstattracted to the guys eyes while everyone elses had been pools of fear,this guy had been calm, wary, intelligent a possible predator.

Anonymous said...

top [url=http://www.c-online-casino.co.uk/]uk casino bonus[/url] brake the latest [url=http://www.realcazinoz.com/]casino[/url] unshackled no store bonus at the foremost [url=http://www.baywatchcasino.com/]bay watch casino
[/url].

Search Linux Resources