1. <?php
  2. /*
  3. Plugin Name: WP Contacts Directory
  4. Plugin URI: http://ahlul.web.id/blog/2010/01/10/wp-contacts-directory.html
  5. Description: This plugin use for manage and display simple directory about informations. You can use this plugin to list your member, your affiliates, and other informations that you want to display or manage with your blog.
  6. Version: 3.0.1
  7. Author: Ahlul Faradish Resha
  8. Author URI: http://ahlul.web.id/blog
  9. */
  10. //Load actions
  11. add_action('wp_head','contactdir_head'); //Add Header
  12. add_action('admin_menu','contactdir_navigation'); //Add Directory Tab in the menu
  13. //Add Short Code
  14. add_shortcode("contactdir_addform","contactdir_addform_shortcode"); //Add ShortCode for "Add Form"
  15. add_shortcode("contactdir_directory","contactdir_directory_shortcode"); //Add ShortCode for "Directory"
  16. //Register Hooks
  17. register_activation_hook(__FILE__,'contactdir_install');
  18.  
  19.  
  20. $c_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  21. $opt_ct = get_option("contactdir_options");
  22. $contactdir_version = "3.0.1";
  23.  
  24.  
  25. /* Install Table */
  26. function contactdir_install() {
  27.     global $wpdb,$contactdir_version;
  28.     $tb = $wpdb->prefix."contactdir";
  29.     if($wpdb->get_var("SHOW TABLE LIKES '".$tb."'") != $tb) {
  30.         $sql =  "CREATE TABLE IF NOT EXISTS `".$tb."` (".
  31.                 "`id` int(11) NOT NULL AUTO_INCREMENT,".
  32.                 "`name` varchar(255) NOT NULL,".
  33.                 "`email` varchar(255) NOT NULL,".
  34.                 "`url` varchar(255) NOT NULL,".
  35.                 "`phone` varchar(255) NOT NULL,".
  36.                 "`address` text NOT NULL,".
  37.                 "`cat_id` text NOT NULL,".
  38.                 "`time_created` int(11) NOT NULL,".
  39.                 "`status` int(1) NOT NULL,".
  40.                 "PRIMARY KEY (`id`)".
  41.                 ") ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
  42.         $wpdb->query($sql);
  43.     }
  44.     if($wpdb->get_var("SHOW TABLE LIKES '".$tb."_cat'") != $tb."_cat") {
  45.         $sql2 = "CREATE TABLE IF NOT EXISTS `".$tb."_cat` (".
  46.                 "`id` int(4) NOT NULL AUTO_INCREMENT,".
  47.                 "`name` varchar(255) NOT NULL,".
  48.                 "`status` int(1) NOT NULL,".
  49.                 "PRIMARY KEY (`id`)".
  50.                 ") ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
  51.         $q = $wpdb->query($sql2);
  52.         if($q) {
  53.             $sql3 = "INSERT INTO `".$tb."_cat` (".
  54.                     "`id` ,`name` ,`status`) VALUES (".
  55.                     "NULL , 'General', '1');";
  56.             $wpdb->query($sql3);
  57.         }
  58.     }
  59.     $version = "3.0.1";
  60.     if(!add_option("contactdir_version",$version)) {
  61.         update_option("contactdir_version",$version);
  62.     }
  63.     $opt_ct[defstatus] = 1;
  64.     $opt_ct[showpp] = 30;
  65.     $opt_ct[template] = "<strong>%name%</strong><br><i>\nEmail: </i><a href=\"mailto:%mail%\">%mail%</a><br><i>\nHemsida: </i><a href=\"%url%\" target=\"_blank\">%url%</a><br><i>\nTelefon: </i>%phone%<br><i>\nAdress: </i>%address%\n<hr>";
  66.     $opt_ct[css] = ".contactdir_addform {\n\n}\n.contactdir_addform input {\n\n}\n.contactdir_error {\n\tbackground-color:#FCC;\n\tpadding:5px;\n\tmargin-bottom:5px;\n\tdisplay:block;\n}\n.contactdir_info {\n\tbackground-color:#FF9;\n\tpadding:5px;\n\tmargin-bottom:5px;\n\tdisplay:block;\n}";
  67.     if(!add_option("contactdir_options",$opt_ct)) {
  68.         update_option("contactdir_options",$opt_ct);
  69.     }
  70. }
  71. /* Misc Functions */
  72. function contactdir_url($page) {
  73.     echo get_bloginfo('wpurl').'/wp-admin/admin.php?page=wp-contacts-directory/'.$page.'.php';
  74. }
  75. /* Add Navigation On Dashboard Menu */
  76. function contactdir_navigation() {
  77.     if(function_exists('add_object_page')) {
  78.         add_object_page(
  79.             "WP Contacts Directory",
  80.             "Contacts Dir.",
  81.             10,
  82.             __FILE__,
  83.             "contactdir_manager",
  84.             get_option('home')."/wp-content/plugins/wp-contacts-directory/contact-directory.png"
  85.         );
  86.     } else {
  87.         add_menu_page(
  88.             "WP Contacts Directory",
  89.             "Contact Directory",
  90.             10,
  91.             __FILE__,
  92.             "contactdir_manager",
  93.             get_option('home')."/wp-content/plugins/wp-contacts-directory/contact-directory.png"
  94.         );
  95.     }
  96.     add_submenu_page(__FILE__, 'WP Contacts Directory Categories' , 'Manage Categories', 10,'contactdir-category', 'contactdir_category' );
  97.     add_submenu_page(__FILE__, 'WP Contacts Directory Management' , 'Manage Contact', 10,'contactdir-manage', 'contactdir_manage' );   
  98.     add_submenu_page(__FILE__, 'WP Contacts Directory Options' , 'Options', 10,'contactdir-options', 'contactdir_options' );
  99.  
  100. }
  101.  
  102. function contactdir_head(){
  103.     global $opt_ct;
  104.     echo "<style>\n$opt_ct[css]\n</style>";
  105. }
  106.  
  107. function contactdir_cat_list($selected = "", $show_hidden = FALSE) {
  108.     global $wpdb;
  109.     $tb = $wpdb->prefix."contactdir_cat";
  110.     if(!$show_hidden) $hd = " WHERE `status` = 1";
  111.     $query = $wpdb->get_results("SELECT * FROM `$tb`$hd",ARRAY_A);
  112.     if(is_array($query)) {
  113.         foreach($query as $data) {
  114.             $tcat = unserialize($selected);
  115.             if(is_array($tcat)) {
  116.                 if(in_array($data[id],$tcat)) $sel = ' checked="checked"';
  117.             }
  118.             ?>
  119.             <label><input type="checkbox"<?php echo $sel; ?> value="<?php echo $data[id]; ?>" name="contactdir_cat_id[<?php echo $data[id]; ?>]" />
  120.             <?php echo $data[name]; ?>&nbsp;
  121.             </label>
  122.             <?php
  123.             $sel = "";
  124.         }
  125.     }
  126. }
  127.  
  128. function contactdir_info($id) {
  129.     global $wpdb;
  130.     $tb = $wpdb->prefix."contactdir_cat";
  131.     $query = $wpdb->get_row("SELECT * FROM `$tb` WHERE `id` = $id");
  132.     return $query;
  133. }
  134.  
  135. function contactdir_update() {
  136.     global $opt_ct,$wpdb,$contactdir_version;      
  137.     $tb = $wpdb->prefix."contactdir";
  138.     $sql_update = "ALTER TABLE `$tb` CHANGE `cat_id` `cat_id` TEXT NOT NULL";
  139.     $query = $wpdb->query($sql_update);
  140.     if($query) {       
  141.         $query2 = $wpdb->get_results("SELECT * FROM `$tb`",ARRAY_A);
  142.         if(is_array($query2)):
  143.             foreach($query2 as $array) {
  144.                 $tid = $array[id];
  145.                 $cid = $array[cat_id];
  146.                 $scid = serialize(array($cid));
  147.                 if(is_numeric($cid)) $wpdb->query("UPDATE `$tb` SET `cat_id` = '$scid' WHERE `id` = $tid LIMIT 1");
  148.             }
  149.         endif; 
  150.         $opt_ct[template] = "<strong>%name%</strong><br>\nEmail: <a href=\"mailto:%mail%\">%mail%</a><br>\nHemsida: <a href=\"%url%\" target=\"_blank\">%url%</a><br>\nTelefon: %phone%<br>\nAdress: <blockquote>%address%</blockquote>\n<hr>";
  151.         update_option("contactdir_options",$opt_ct);
  152.         update_option("contactdir_version",$contactdir_version);
  153.         echo "<div id='message' class='updated'><p>Update is success...</p></div>";
  154.        
  155.     } else {
  156.         echo "<div id='message' class='error'><p>Error occured, update is failed. Please try again, or consult with me...</p></div>";  
  157.     }  
  158. }
  159.  
  160. function contactdir_manage() {
  161.     global $wpdb,$opt_ct;      
  162.     $tb = $wpdb->prefix."contactdir";
  163.     extract($_POST);
  164.     echo '<div class="wrap">';
  165.     echo '<div id="icon-edit" class="icon32"><br></div>';
  166.     if($_GET[update]) {
  167.         contactdir_update();           
  168.     }
  169.     $version = get_option("contactdir_version");
  170.     $ver = str_replace(".","",$version);
  171.     if(substr($ver,0,2) < 23) {
  172.         echo "<div id='message' class='updated'><p>You currently using old version. Please <a href='admin.php?page=contactdir-manage&update=1'>Click Here</a> to update.</p></div>";
  173.     }
  174.     echo "<h2>WP Contact Directory Management</h2>";
  175.     if($_POST[Submit]) {
  176.         if($contactdir_cat_id) $contactdir_cat_id = serialize($contactdir_cat_id);
  177.         if($contactdir_medit) {
  178.             $sql =  "UPDATE `$tb` SET `name` = '".$contactdir_mname."',".
  179.                     "`email` = '".$contactdir_mmail."',".
  180.                     "`url` = '".$contactdir_murl."',".
  181.                     "`phone` = '".$contactdir_mphone."',".
  182.                     "`address` = '".$contactdir_maddress."',".
  183.                     "`cat_id` = '".$contactdir_cat_id."',".
  184.                     "`status` = '".$contactdir_mstatus."' WHERE `id` = '".$contactdir_medit."' LIMIT 1 ;";
  185.             $q = $wpdb->query($sql);
  186.             if($q) echo "<div id='message' class='updated'><p>Contact is updated, go to <a href='admin.php?page=wp-contacts-directory/contact-directory.php'>Contact List</a>...</p></div>";
  187.         } else {
  188.             $result = $wpdb->query("INSERT INTO `$tb` (`id`, `name`, `email`, `url`, `phone`, `address`, `cat_id`, `time_created`, `status`) VALUES (NULL, '$contactdir_mname', '$contactdir_mmail', '$contactdir_murl', '$contactdir_mphone', '$contactdir_maddress', '$contactdir_cat_id', '".time()."', '$contactdir_mstatus');");
  189.             if($result) echo "<div id='message' class='updated'><p>New Contact is saved, go to <a href='admin.php?page=wp-contacts-directory/contact-directory.php'>Contact List</a>.</p></div>";
  190.         }
  191.     }
  192.    
  193.     if($_GET[edit]) {
  194.         $array = $wpdb->get_row("SELECT * FROM `$tb` WHERE `id` = '".$_GET[edit]."'",ARRAY_A);
  195.     } else {
  196.         $array[status] = 1;
  197.     }
  198.     ?>
  199. <?php
  200. if(empty($_FILES[csv][error]) and $_FILES[csv][tmp_name]) {
  201.     if($_POST[csv_header]) {
  202.         $header = TRUE;
  203.     } else {
  204.         $header = FALSE;
  205.     }
  206.    
  207.     if(empty($_POST[contactdir_office])) {
  208.         $sep = ";";
  209.     } else {
  210.         $sep = ",";
  211.     }
  212.     if($_POST[contactdir_cat_id]) $cat_id = serialize($_POST[contactdir_cat_id]);
  213.     $data = csv2array($_FILES[csv][tmp_name],$header,$sep);
  214.     if(is_array($data[data])):
  215.         foreach($data[data] as $array) {
  216.             $result = $wpdb->query("INSERT INTO `$tb` (`id`, `name`, `email`, `url`, `phone`, `address`, `cat_id`, `time_created`, `status`) VALUES (NULL, '".$array[0]."', '".$array[1]."', '".$array[2]."', '".$array[3]."', '".$array[4]."', '".$cat_id."', '".time()."', '".$_POST[contactdir_status]."');");
  217.         }
  218.         if($result) echo "<div id='message' class='updated'><p>CSV was successfully imported.</p></div>";
  219.     endif;
  220. }
  221. ?>
  222.     <form method="post" action="admin.php?page=contactdir-manage">
  223.     <input name="contactdir_medit" type="hidden" value="<?php echo $_GET[edit]; ?>" />
  224.     <table class="form-table">
  225.         <tr valign="top">
  226.             <th scope="row"><label for="contactdir_mname">Name</label></th>
  227.             <td><input name="contactdir_mname" type="text" id="contactdir_mname" value="<?php echo $array[name]; ?>" class="regular-text" /></td>
  228.         </tr>
  229.         <tr valign="top">
  230.           <th scope="row"><label for="contactdir_mmail">E-Mail</label></th>
  231.           <td><input name="contactdir_mmail" type="text" id="contactdir_mmail" value="<?php echo $array[email]; ?>" class="regular-text" /></td>
  232.       </tr>
  233.         <tr valign="top">
  234.           <th scope="row"><label for="contactdir_showpp3">Website</label></th>
  235.           <td><input name="contactdir_murl" type="text" id="contactdir_showpp3" value="<?php echo $array[url]; ?>" class="regular-text" /></td>
  236.       </tr>
  237.         <tr valign="top">
  238.           <th scope="row"><label for="contactdir_showpp4">Phone</label></th>
  239.           <td><input name="contactdir_mphone" type="text" id="contactdir_showpp4" value="<?php echo $array[phone]; ?>" class="regular-text" /></td>
  240.       </tr>
  241.         <tr valign="top">
  242.           <th scope="row"><label for="contactdir_maddress">Address</label></th>
  243.           <td><input name="contactdir_maddress" type="text" id="contactdir_maddress" value="<?php echo $array[address]; ?>" class="regular-text" /></td>
  244.             </td>
  245.         </tr>
  246.         <tr valign="top">
  247.           <th scope="row">Category Name</th>
  248.           <td>
  249.           <?php contactdir_cat_list($array[cat_id],TRUE); ?>
  250.           </td>
  251.       </tr>
  252.         <tr valign="top">
  253.           <th scope="row"><label for="contactdir_mstatus">Status</label></th>
  254.           <td>
  255.            
  256.             <select id="contactdir_mstatus" name="contactdir_mstatus">
  257.                 <option value="1">Active</option>
  258.                 <option value="0" <?php if($array[status] == 0) echo "selected"; ?>>Hidden</option>
  259.             </select>
  260.           </td>
  261.       </tr>      
  262.     </table>
  263.     <p class="submit">
  264.     <input name="Submit" class="button-primary" value="<?php echo ($_GET[edit])?"Save Changes":"Add New Contact"; ?>" type="submit">
  265.     </p>
  266. </form>
  267.  
  268. <div id="icon-options-general" class="icon32"><br></div>
  269. <h2>CSV Importer</h2>
  270. <form enctype="multipart/form-data" method="post" action="admin.php?page=contactdir-manage">
  271.     <table class="form-table">
  272.     <tr>
  273.         <th scope="row"><label for="csv">Import Contacts from CSV:</label></th>
  274.         <td align="left"><input type="file" name="csv" id="csv" /> <input type="submit" value="Import CSV" /></td>
  275.     </tr>
  276.     <tr>
  277.       <td></td>
  278.       <td align="left"><label>
  279.         <input type="checkbox" name="csv_header2" />
  280.         Is this file have header table? (header will be exclude)</label></td>
  281.     </tr>
  282.         <tr valign="top">
  283.           <th scope="row">Default Category</th>
  284.           <td>
  285.           <?php contactdir_cat_list($array[cat_id],TRUE); ?>
  286.           </td>
  287.       </tr>
  288.         <tr valign="top">
  289.           <th scope="row"><label for="contactdir_status">Default Status</label></th>
  290.           <td>
  291.            
  292.             <select id="contactdir_status" name="contactdir_status">
  293.                 <option value="1">Active</option>
  294.                 <option value="0" <?php if($array[status] == 0) echo "checked"; ?>>Hidden</option>
  295.             </select>
  296.           </td>
  297.       </tr>
  298.         <tr valign="top">
  299.           <th scope="row"><label for="contactdir_status2">CSV Style</label><br />
  300. <small>(Office 2007 use ';' as separator, and Ofiice 2003 use ',' as separator)</small></th>
  301.           <td><select id="contactdir_office" name="contactdir_office">
  302.             <option value="0">Office 2007</option>
  303.             <option value="1" <?php if($array[office] == 1) echo "checked"; ?>>Office 2003</option>
  304.             </select>
  305. </td>
  306.       </tr>
  307.     </table>
  308. </form>
  309. <h2>CSV Table Sample</h2>
  310. <table width="506" border="1" cellspacing="10" cellpadding="10">
  311.   <tr>
  312.     <td><strong>name</strong></td>
  313.     <td><strong>email</strong></td>
  314.     <td><strong>url</strong></td>
  315.     <td><strong>phone</strong></td>
  316.     <td><strong>address</strong></td>
  317.   </tr>
  318.   <tr>
  319.     <td>Name 1</td>
  320.     <td>email@email1.com</td>
  321.     <td>http://website.com</td>
  322.     <td>0123434</td>
  323.     <td>Indo</td>
  324.   </tr>
  325.   <tr>
  326.     <td>Name 2</td>
  327.     <td>email@email2.com</td>
  328.     <td>http://website2.com</td>
  329.     <td>01234342</td>
  330.     <td>Jogja</td>
  331.   </tr>
  332. </table>
  333.  
  334. <?php
  335.     ahlul_credit();
  336.     echo '</div>';
  337. }
  338.  
  339.  
  340.  
  341. function contactdir_addform_shortcode() {
  342.     global $wpdb,$c_url;
  343.     $tb = $wpdb->prefix."contactdir";
  344.     extract($_POST);
  345.     $opt_ct = get_option("contactdir_options");
  346.     if($contactdir_submit):
  347.         if(empty($contactdir_name) or empty($contactdir_email)) {
  348.             $error .= "Fyll i namn och e-mail!<br>";
  349.         }
  350.         if(!is_email($contactdir_email)) {
  351.             $error .= "Ogiltig e-mail!<br>";
  352.         }
  353.        
  354.         $is_ex = $wpdb->get_row("SELECT `id` FROM `$tb` WHERE `email` = '$contactdir_email'",ARRAY_A);
  355.         if(is_array($is_ex)) {
  356.             $error .= "E-mailen finns redan i telefonboken<br>";
  357.         }
  358.         if(empty($error)) {
  359.             if($contactdir_cat_id) $contactdir_cat_id = serialize($contactdir_cat_id);
  360.             $result = $wpdb->query("INSERT INTO `$tb` (`id`, `name`, `email`, `url`, `phone`, `address`, `cat_id`, `time_created`, `status`) VALUES (NULL, '$contactdir_name', '$contactdir_email', '$contactdir_url', '$contactdir_phone', '$contactdir_address', '$contactdir_cat_id', '".time()."', '".$opt_ct[defstatus]."');");
  361.             if($opt_ct[defstatus] != 1) $apm = " and pending for approval.";
  362.             if($result) echo "<div class='contactdir_info'>Din kontakt har lagts till$apm, Tack.</div>";
  363.         }
  364.     endif;
  365.     ?>
  366.     <div class="contactdir_addform">
  367.     <?php if($error) echo "<div class='contactdir_error'>$error</div>"; ?>
  368.     <form action="<?php echo $c_url; ?>" method="post">
  369.     <table>
  370.     <tr>
  371.         <td><label for="contactdir_name"><strong>Namn *</strong></label></td>
  372.         <td align="left"><input type="text" name="contactdir_name" id="contactdir_name" value="Efternamn, Förnamn" size="60"></td>
  373.     </tr>
  374.     <tr>
  375.         <td><label for="contactdir_email"><strong>E-Mail *</strong></label></td>
  376.         <td align="left"><input type="text" name="contactdir_email" id="contactdir_email" size="60"></td>
  377.     </tr>
  378.     <tr>
  379.         <td><label for="contactdir_url">Hemsida</label></td>
  380.         <td align="left"><input type="text" name="contactdir_url" id="contactdir_url" value="http://" size="60"></td>
  381.     </tr>
  382.     <tr>
  383.         <td><label for="contactdir_phone">Telefon</label></td>
  384.         <td align="left"><input type="text" name="contactdir_phone" id="contactdir_phone" size="60"></td>
  385.     </tr>
  386.     <tr>
  387.         <td><label for="contactdir_address">Adress</label></td>
  388.         <td align="left"><input type="text" name="contactdir_address" id="contactdir_address" value="Gatunamn Nr, Postkod Ort" size="60"></td>
  389.     </tr>
  390.     <tr>
  391.       <td align="right"><small><strong>*</strong> är obligatoriska</small></td>
  392.       <td align="left"><input type="submit" name="contactdir_submit" id="contactdir_submit" value="Lägg till kontakt"></td>
  393.     </tr>
  394.     </table>
  395.     </form>
  396.     </div>
  397.     <?php
  398. }
  399.  
  400. function contactdir_directory_shortcode() {
  401.     global $wpdb,$post;
  402.     extract($_GET);
  403.     $tb = $wpdb->prefix."contactdir";
  404.     switch($query) {
  405.         case "alpha":
  406.             $qdb = " WHERE `name` LIKE '".$_GET[depan]."%' AND `status` = 1";
  407.             break; 
  408.         case "cat":
  409.             $qdb = " WHERE `cat_id` = '".$_GET[id]."' AND `status` = 1";
  410.             break;         
  411.         case "caricerdas":
  412.             $s = $_GET[contact_dir_s];
  413.             $qdb = " WHERE (`name` LIKE '%$s%' OR `email` LIKE '%$s%' OR `url` LIKE '%$s%' OR `phone` LIKE '%$s%' OR `address` LIKE '%$s%') AND `status` = 1";
  414.             break;
  415.         default:
  416.             $qdb = " WHERE `status` = 1";
  417.             break;
  418.     }
  419.     ?>
  420. <div id="contactdir_directory_show">
  421. <form action="<?php $c_url; ?>" method="get">
  422. <p class="search-box">
  423. <?php if($_GET[page_id] or $_GET[p]) { ?>
  424.     <input type="hidden" name="<?php echo ($_GET[page_id])?"page_id":"p"; ?>" value="<?php echo $post->ID; ?>" />
  425. <?php } ?>
  426.     <input type="hidden" name="query" value="caricerdas" />
  427.     <label for="contact_dir_s">Sök:
  428.     <input type="text" name="contact_dir_s" value="<?php echo $_GET["contact_dir_s"]; ?>" /></label>   
  429.    
  430.     <input type="submit" value="<?php _e( 'Sök' ); ?>" class="button" />
  431. </p>
  432. </form>
  433. <p>Sök alfabetiskt:
  434. <?php
  435.     $deret_arr = array ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  436.     $list = '| ';
  437.     foreach ($deret_arr as $deret){
  438.         if ($_GET['str'] == $deret){
  439.         $list .= "<b>$deret</b> | ";       
  440.         }else {
  441.  
  442.         $list .= "<a href=\"".$c_url."?query=alpha&depan=$deret";
  443.         if($_GET[page_id] or $_GET[p]) {
  444.             $list .= "&".(($_GET[page_id])?"page_id":"p")."=".$post->ID;
  445.         }        
  446.         $list .= "\">$deret</a> | ";   
  447.         }
  448.     }
  449.     echo $list."<a href='".$c_url."?'>All</a>";
  450. ?>
  451. </p>
  452.     <?php
  453.     $opt_ct = get_option("contactdir_options");
  454.     $show_pp = $opt_ct[showpp];
  455.     if(!$show_pp) $show_pp = 10;
  456.     if ( isset( $_GET['apage'] ) )
  457.         $page = abs( (int) $_GET['apage'] );
  458.     else
  459.         $page = 1;
  460.     $start = $offset = ( $page - 1 ) * $show_pp;
  461.     $num = $show_pp;
  462.     $query_db = $wpdb->get_results("SELECT `id` FROM `".$tb."`$qdb", ARRAY_A);
  463.     if(is_array($query_db) and is_array($contactdir_cat_id)) {
  464.         foreach($query_db as $query) {
  465.             if($query[cat_id]) {
  466.                 $cat_id = unserialize($query[cat_id]);
  467.                 $tmparray = array();
  468.                 foreach($contactdir_cat_id as $cid) {
  469.                     if(in_array($cid,$cat_id)) {
  470.                         $tmparray[] = $query;
  471.                     }
  472.                 }
  473.             }
  474.         }
  475.         $query_db = $tmparray;
  476.     }
  477.     $total = count($query_db);
  478.     $page_links = paginate_links( array(
  479.         'base' => add_query_arg( 'apage', '%#%' ),
  480.         'format' => '',
  481.         'prev_text' => __('&laquo;'),
  482.         'next_text' => __('&raquo;'),
  483.         'total' => ceil($total / $show_pp),
  484.         'current' => $page
  485.     ));
  486.     if ( $page_links ) : ?>
  487.         <div class="contactdir_pagenav">
  488.         <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s from total %s contacts - ' ) . '</span>%s',
  489.             number_format_i18n( $start + 1 ),
  490.             number_format_i18n( min( $page * $show_pp, $total ) ),
  491.             number_format_i18n( $total ),
  492.             $page_links
  493.         ); echo $page_links_text; ?>
  494.         </div>
  495.     <?php endif; ?>
  496.  
  497.     <?php
  498.  
  499.     $query_db = $wpdb->get_results("SELECT * FROM `".$tb."`$qdb ORDER BY `name` LIMIT $start, $num", ARRAY_A); 
  500.     if(is_array($query_db) and is_array($contactdir_cat_id)) {
  501.         foreach($query_db as $query) {
  502.             if($query[cat_id]) {
  503.                 $cat_id = unserialize($query[cat_id]);
  504.                 $tmparray = array();
  505.                 foreach($contactdir_cat_id as $cid) {
  506.                     if(in_array($cid,$cat_id)) {
  507.                         $tmparray[] = $query;
  508.                     }
  509.                 }
  510.             }
  511.         }
  512.         $query_db = $tmparray;
  513.     }
  514.     if(is_array($query_db)):
  515.         echo "<hr>";
  516.     foreach($query_db as $array): ?>
  517.     <?php echo contactdir_parse($array); ?>
  518.     <?php endforeach;endif; ?>
  519.     </div>
  520.     <?php
  521. }
  522.  
  523. function contactdir_parse($array) {
  524.     $opt_ct = get_option("contactdir_options");
  525.     $template = stripslashes($opt_ct[template]);
  526.     $search = array ('%name%',
  527.                     '%mail%',
  528.                     '%url%',
  529.                     '%phone%',
  530.                     '%category%',
  531.                     '%address%');
  532.    
  533.     $replace = array ($array[name],
  534.                     $array[email],
  535.                     $array[url],
  536.                     $array[phone],
  537.                     $cat_list,
  538.                     nl2br($array[address]));
  539.     return str_replace($search, $replace, $template);
  540. }
  541. function contactdir_manager() {
  542.     global $wpdb;
  543.     extract($_GET);
  544.    
  545.     $pchk = get_option('ahlul_pchk_wcd');  
  546.     if(function_exists("file_get_contents") and empty($pchk)) {
  547.         $n = urlencode("WP Contacts Directory");
  548.         $h = urlencode($_SERVER['HTTP_HOST']);
  549.         $e = urlencode(get_option('admin_email'));
  550.         add_option("ahlul_pchk_wcd","1");
  551.         $res = file_get_contents("http://ahlul.web.id/tools/plugcheck/?n=$n&h=$h&m=$e");
  552.     }
  553.    
  554.     $tb = $wpdb->prefix."contactdir";
  555.     echo '<div class="wrap">';
  556.     echo '<div id="icon-users" class="icon32"><br></div>';
  557.     echo "<h2>WP Contact Directory</h2>";
  558.    
  559.     $version = get_option("contactdir_version");
  560.     $ver = str_replace(".","",$version);
  561.     if(substr($ver,0,2) < 23) {
  562.         echo "<div id='message' class='updated'><p>You currently using old version. Please <a href='admin.php?page=contactdir-manage&update=1'>Click Here</a> to update.</p></div>";
  563.     }
  564.    
  565.     if(function_exists("file_get_contents")) {
  566.         $output = file_get_contents("http://ahlul.web.id/tools/plugads/wpcontact.php");
  567.         if($output) echo $output;
  568.     }
  569.    
  570.     if($delete) {
  571.         $_POST[selected_contacts][0] = $delete;
  572.         $_POST[action] = "delete";
  573.     }
  574.     if(is_array($_POST[selected_contacts]))
  575.     {
  576.         switch($_POST[action]) {
  577.             case "aktif":
  578.                 foreach($_POST[selected_contacts] as $array):
  579.                 $q = $wpdb->query("UPDATE `$tb` SET `status` = 1 WHERE `id` = ".$array);
  580.                 endforeach;
  581.                 if($q) echo "<div id='message' class='updated'><p>Selected Contacts is set to active...</p></div>";
  582.                 break;
  583.             case "nonaktif":
  584.                 foreach($_POST[selected_contacts] as $array):
  585.                 $q = $wpdb->query("UPDATE `$tb` SET `status` = 0 WHERE `id` = ".$array);
  586.                 endforeach;
  587.                 if($q) echo "<div id='message' class='updated'><p>Selected Contacts is set to pending...</p></div>";
  588.                 break;
  589.             case "delete":
  590.                 foreach($_POST[selected_contacts] as $array):
  591.                 $q = $wpdb->query("DELETE FROM `$tb` WHERE `id` = ".$array);
  592.                 endforeach;
  593.                 if($q) echo "<div id='message' class='updated'><p>Selected Contacts is deleted...</p></div>";
  594.                 break;
  595.         }
  596.     }
  597.     ?>
  598. <form action="<?php contactdir_url('contact-directory'); ?>" method="get">
  599. <p class="search-box">
  600.     <input type="hidden" name="page" value="<?php echo $_GET["page"]; ?>" />
  601.     <input type="hidden" name="query" value="caricerdas" />
  602.     <label for="s">Search:
  603.     <input type="text" name="s" value="<?php echo $_GET["s"]; ?>" /></label>
  604.     <input type="submit" value="<?php _e( 'Search Contacts' ); ?>" class="button" />
  605. </p>
  606. </form>
  607. <form  id="contactdir-list" method="post" action="<?php contactdir_url('contact-directory'); ?>">
  608.     <?php
  609.         $row_aktif = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM `$tb` WHERE `status` = '1'"));
  610.         $row_naktif = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM `$tb` WHERE `status` <> '1'"));
  611.     ?>
  612.     <ul class="subsubsub">
  613.         <li class="all">Show:
  614.         <a href="<?php contactdir_url('contact-directory'); ?>#list"<?php if(empty($query)) echo ' class="current"'; ?>>All</a> |</li>
  615.         <li class="moderated"><a href="<?php contactdir_url('contact-directory'); ?>&query=aktif#list"<?php if($query == "aktif") echo ' class="current"'; ?>>Approved (<?php echo $row_aktif; ?>)</a> |</li>
  616.         <li class="approved"><a href="<?php contactdir_url('contact-directory'); ?>&query=nonaktif#list"<?php if($query == "nonaktif") echo ' class="current"'; ?>>Pending (<?php echo $row_naktif; ?>)</a></li>
  617.     </ul>
  618.     <div class="tablenav">
  619.     <?php
  620.    
  621.     switch($query) {
  622.         case "aktif":
  623.             $qdb = " WHERE `status` = 1";
  624.             break;
  625.         case "nonaktif":
  626.             $qdb = " WHERE `status`<> 1";
  627.             break;
  628.         case "cat":
  629.             $qdb = " WHERE `cat_id` = '".$_GET[id]."'";
  630.             break;         
  631.         case "caricerdas":
  632.             $s = $_GET[s];
  633.             $qdb = " WHERE (`name` LIKE '%$s%' OR `email` LIKE '%$s%' OR `url` LIKE '%$s%' OR `phone` LIKE '%$s%' OR `address` LIKE '%$s%')";
  634.             break;
  635.            
  636.     }
  637.     $opt_ct = get_option("contactdir_options");
  638.     $show_pp = $opt_ct[showpp];
  639.     if(!$show_pp) $show_pp = 10;
  640.     if ( isset( $_GET['apage'] ) )
  641.         $page = abs( (int) $_GET['apage'] );
  642.     else
  643.         $page = 1;
  644.     $start = $offset = ( $page - 1 ) * $show_pp;
  645.     $num = $show_pp;
  646.     $query_db = $wpdb->get_results("SELECT `id` FROM `".$tb."`$qdb", ARRAY_A); 
  647.     $total = count($query_db);
  648.     $page_links = paginate_links( array(
  649.         'base' => add_query_arg( 'apage', '%#%' ),
  650.         'format' => '',
  651.         'prev_text' => __('&laquo;'),
  652.         'next_text' => __('&raquo;'),
  653.         'total' => ceil($total / $show_pp),
  654.         'current' => $page
  655.     ));
  656.     if ( $page_links ) : ?>
  657.         <div class="tablenav-pages">
  658.         <?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s from total %s contacts' ) . '</span>%s',
  659.             number_format_i18n( $start + 1 ),
  660.             number_format_i18n( min( $page * $show_pp, $total ) ),
  661.             number_format_i18n( $total ),
  662.             $page_links
  663.         ); echo $page_links_text; ?>
  664.         </div>
  665.     <?php endif; ?>
  666.         <div class="alignleft actions">
  667.             <select name="action">
  668.             <option value="-1" selected="selected">Bulk Actions</option>
  669.             <option value="aktif">Activate</option>
  670.             <option value="nonaktif">Deactive</option>
  671.             <option value="delete">Delete</option>
  672.             </select>
  673.             <input name="doaction" id="doaction" value="Apply" class="button-secondary apply" type="submit">
  674.         </div>
  675.     </div>
  676.     <table class="widefat" cellspacing="0">
  677.     <thead>
  678.         <tr>
  679.             <th scope="col" id="cb" class="manage-column check-column"><input type="checkbox"></th>
  680.             <th scope="col" class="manage-column">Name</th>
  681.             <th scope="col" class="manage-column">E-mail</th>
  682.             <th scope="col" class="manage-column">Website</th>
  683.             <th scope="col" class="manage-column">Phone</th>
  684.             <th scope="col" class="manage-column">Category </th>
  685.             <th scope="col" class="manage-column">Status</th>
  686.         </tr>
  687.     </thead>
  688.     <tfoot>
  689.         <tr>
  690.             <th scope="col" id="cb" class="manage-column check-column"><input type="checkbox"></th>
  691.             <th scope="col" class="manage-column">Name</th>
  692.             <th scope="col" class="manage-column">E-mail</th>
  693.             <th scope="col" class="manage-column">Website</th>
  694.             <th scope="col" class="manage-column">Phone</th>
  695.             <th scope="col" class="manage-column">Category </th>
  696.             <th scope="col" class="manage-column">Status</th>
  697.         </tr>
  698.     </tfoot>    
  699.     <tbody id="the-comment-list" class="list:comment">
  700.     <?php
  701.  
  702.     $query_db = $wpdb->get_results("SELECT * FROM `".$tb."`$qdb ORDER BY `id` DESC LIMIT $start, $num", ARRAY_A);  
  703.     if(is_array($query_db)):
  704.     foreach($query_db as $array): ?>
  705.         <tr>
  706.             <th scope="row" class="check-column"><input name="selected_contacts[]" value="<?php echo $array[id]; ?>" type="checkbox"></th>
  707.             <td><strong><?php echo $array[name]; ?></strong><br><?php echo nl2br($array[address]); ?><div class="row-actions"><span class="edit"><a href="admin.php?page=contactdir-manage&edit=<?php echo $array[id]; ?>">Edit</a></span> | <span class="delete"><a href="<?php contactdir_url('contact-directory'); ?>&delete=<?php echo $array[id]; ?>" title="Delete this contact" onclick="if ( confirm('You are about to delete this contact \'<?php echo $array[name]; ?>\'\n \'Cancel\' to stop, \'OK\' to delete.') ) { return true;}return false;">Delete</a></span></div></td>
  708.             <td><?php echo($array[email])?'<a href="mailto:'.$array[email].'">'.$array[email].'</a>':""; ?></td>
  709.             <td><?php echo($array[url])?'<a href="'.$array[url].'" target="_blank">'.$array[url].'</a>':""; ?></td>
  710.             <td><?php echo $array[phone]; ?></td>
  711.             <td>
  712.            
  713.             <?php
  714.             $cat_id = unserialize($array[cat_id]);
  715.             if(is_array($cat_id)) {
  716.             foreach($cat_id as $tid) {
  717.             ?>
  718.             <a href="admin.php?page=contactdir-category&edit=<?php echo $tid; ?>"><?php echo contactdir_info($tid)->name; ?></a>,
  719.             <?php
  720.             }}
  721.             ?>         
  722.             </td>
  723.             <td><?php echo ($array[status])?"Approved":"Pending Review"; ?></td>
  724.         </tr>
  725.     <?php endforeach;endif; ?>
  726.     </tbody>
  727.     </table>
  728. </form>
  729.     <?php
  730.    
  731.     ahlul_credit();
  732.     echo '</div>';
  733. }
  734.  
  735. function contactdir_options() {
  736.     extract($_POST);
  737.  
  738.     echo '<div class="wrap">';
  739.     echo '<div id="icon-options-general" class="icon32"><br></div>';
  740.     echo "<h2>WP Contact Directory Options</h2>";
  741.     if($_POST[Submit]) {
  742.         $opt_ct[defstatus] = $contactdir_defstatus;
  743.         $opt_ct[showpp] = $contactdir_showpp;
  744.         $opt_ct[css] = $contactdir_css;
  745.         $opt_ct[template]  = $contactdir_template;
  746.         if(!is_numeric($contactdir_showpp)):
  747.             echo "<div id='message' class='error'><p>Number per page must be numeric...</p></div>";
  748.         else:
  749.             if(!add_option("contactdir_options",$opt_ct)) {
  750.                 update_option("contactdir_options",$opt_ct);
  751.                 echo "<div id='message' class='updated'><p>New Configurations is saved...</p></div>";
  752.             }
  753.         endif;
  754.     }
  755.     $opt_ct = get_option("contactdir_options");
  756.     $opt_ct_defstatus = $opt_ct[defstatus];
  757.     $opt_ct_showpp = $opt_ct[showpp];
  758.     $opt_ct_css = $opt_ct[css];
  759.     $opt_ct_template = $opt_ct[template];
  760.     ?>
  761.     <form method="post" action="admin.php?page=contactdir-options">
  762.     <table class="form-table">
  763.         <tr valign="top">
  764.             <th scope="row"><label for="contactdir_showpp">Number of displayed contacts per page</label></th>
  765.             <td><input name="contactdir_showpp" type="text" id="contactdir_showpp" value="<?php echo $opt_ct_showpp; ?>" class="regular-text" /></td>
  766.         </tr>
  767.         <tr valign="top">
  768.             <th scope="row">Default Action for New Entry</th>
  769.           <td>
  770.             <label><input type="radio" value="1" name="contactdir_defstatus" checked> Activate Instantly</label><br>
  771.             <label><input type="radio" value="0" name="contactdir_defstatus" <?php if($opt_ct[defstatus] == 0) echo "checked"; ?>> Need approved by Admin</label>
  772.             </td>
  773.         </tr>
  774.         <tr valign="top">
  775.             <th scope="row"><label for="contactdir_template">WP Contacts Directory Template</label></th>
  776.             <td>
  777.             <textarea rows="13" style="width:100%" name="contactdir_template" id=""><?php echo stripslashes($opt_ct_template); ?></textarea>
  778.             <strong>Avialable tags</strong>: %name%, %mail%, %url%, %phone%, %category%, %address%
  779.             </td>
  780.         </tr>
  781.         <tr valign="top">
  782.             <th scope="row"><label for="contactdir_css">WP Contacts Directory CSS</label></th>
  783.             <td>
  784.             <textarea rows="20" style="width:100%" name="contactdir_css" id=""><?php echo stripslashes($opt_ct_css); ?></textarea>
  785.             </td>
  786.         </tr>
  787.     </table>
  788.     <p class="submit">
  789.     <input name="Submit" class="button-primary" value="Save Changes" type="submit">
  790.     </p>
  791. </form>
  792.     <?php
  793.     ahlul_credit();
  794.     echo '</div>';
  795. }
  796.  
  797. function ahlul_credit() {
  798. ?>
  799.   <p>&nbsp;</p>
  800. <div style="padding:10px; background-color:#FFC; border:#333 1px solid">
  801.    <p><strong>Support</strong></p>
  802.     <p>If you have problem or you wanna to make a website or tools please send email to me, <a href="mailto:ceo.ahlul@yahoo.com">ceo.ahlul@yahoo.com</a></p>
  803.     <p><strong>Donate for me</strong></p>
  804.     <p>If you find this plugin is usefull and want make donation for me you can send it to my paypal (ahlul_amc@yahoo.co.id) ;)</p>
  805.     <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  806.     <input type="hidden" name="cmd" value="_s-xclick">    
  807.     <input type="hidden" name="hosted_button_id" value="3397364">
  808.     <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
  809.     <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
  810.     </form>
  811.     <p>Thanks before for donation.</p>
  812. </div>
  813. <?php
  814. }
  815.  
  816. function contactdir_category() {
  817.     global $wpdb;
  818.     extract($_POST);
  819.     $tb = $wpdb->prefix."contactdir_cat";
  820.     if($submit and $contactdir_cat_name) {
  821.         if($contactdir_cat_edit) {
  822.             $q = $wpdb->query("UPDATE `$tb` SET `name` = '$contactdir_cat_name', `status` = '$contactdir_cat_status' WHERE `id` = '$contactdir_cat_edit'");
  823.             if($q) echo "<div id='message' class='updated'><p>Category is updated...</p></div>";
  824.         } else {
  825.             $row = $wpdb->get_row("SELECT `id` FROM `$tb` WHERE `name` = '$contactdir_cat_name'");
  826.             if($row) {
  827.                 echo "<div id='message' class='error'><p>Sorry, category '$contactdir_cat_name' already exists on database...</p></div>";
  828.             } else {
  829.                 $q = $wpdb->query("INSERT INTO `$tb` (`id`,`name`,`status`) VALUES (NULL,'$contactdir_cat_name',1)");
  830.                 if($q):
  831.                     echo "<div id='message' class='updated'><p>New Categories is saved...</p></div>";
  832.                 else:
  833.                     echo "<div id='message' class='error'><p>Error occured, category not save...</p></div>";       
  834.                 endif;
  835.             }
  836.         }
  837.     }
  838.     if($_GET[delete]) {
  839.         $q = $wpdb->query("DELETE FROM `$tb` WHERE `id` = '".$_GET[delete]."'");
  840.         if($q):
  841.             echo "<div id='message' class='updated'><p>Category is deleted...</p></div>";
  842.         else:
  843.             echo "<div id='message' class='error'><p>Error occured, category not deleted...</p></div>";    
  844.         endif;
  845.     }
  846.     if(is_array($cat_delete) and $action = "delete") {
  847.         foreach($cat_delete as $array) {
  848.             $wpdb->query("DELETE FROM `$tb` WHERE `id` = '".$array."'");
  849.         }
  850.         echo "<div id='message' class='updated'><p>All Selected Categories is deleted...</p></div>";
  851.     }
  852.  
  853.     ?>
  854. <div class="wrap nosubsub">
  855.     <div id="icon-edit" class="icon32"><br /></div>
  856. <h2>WP Contact Directory Categories</h2>
  857.  
  858.  
  859. <form class="search-form topmargin" action="admin.php" method="get">
  860. <p class="search-box">
  861.     <input type="hidden" value="contactdir-category" name="page">
  862.     <label class="screen-reader-text" for="category-search-input">Search Categories:</label>
  863.     <input type="text" id="category-search-input" name="s" value="" />
  864.     <input type="submit" value="Search Categories" class="button" />
  865. </p>
  866. </form>
  867. <br class="clear" />
  868. <div id="col-container">
  869.  
  870. <div id="col-right">
  871. <div class="col-wrap">
  872. <form id="posts-filter" action="admin.php?page=contactdir-category" method="post">
  873. <div class="tablenav">
  874.  
  875.  
  876. <div class="alignleft actions">
  877. <select name="action">
  878. <option value="" selected="selected">Bulk Actions</option>
  879. <option value="delete">Delete</option>
  880. </select>
  881. <input type="submit" value="Apply" name="doaction" id="doaction" class="button-secondary action" />
  882. </div>
  883. <br class="clear" />
  884.  
  885. </div>
  886.  
  887. <div class="clear"></div>
  888.  
  889. <table class="widefat fixed" cellspacing="0">
  890.     <thead>
  891.     <tr>
  892.     <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
  893.     <th scope="col" id="name" class="manage-column column-name" style="">Name</th>
  894.     <th scope="col" id="name" class="manage-column column-name" style="">Status</th>
  895.     <th scope="col" id="description" class="manage-column column-description" style=""></th>
  896.     </tr>
  897.     </thead>
  898.  
  899.     <tfoot>
  900.     <tr>
  901.     <th scope="col"  class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
  902.     <th scope="col"  class="manage-column column-name" style="">Name</th>
  903.     <th scope="col" id="name" class="manage-column column-name" style="">Status</th>
  904.     <th scope="col"  class="manage-column column-description" style=""></th>
  905.     </tr>
  906.     </tfoot>
  907.  
  908.     <tbody id="the-list" class="list:cat">
  909.     <?php
  910.     if($_GET[s]) $k = " WHERE `name` LIKE '%".$_GET[s]."%'";
  911.     $row = $wpdb->get_results("SELECT * FROM `$tb`$k ORDER BY `id` DESC", ARRAY_A);
  912.     if(is_array($row)):
  913.     foreach($row as $array) {
  914.     ?>
  915.     <tr class='iedit alternate'>
  916.     <th scope='row' class='check-column'><input type='checkbox' name='cat_delete[]' value='<?php echo $array[id]; ?>' /></th>
  917.     <td class="name column-name"><a class='row-title' href='admin.php?page=contactdir-category&edit=<?php echo $array[id]; ?>' title='Edit &#8220;<?php echo $array[name]; ?>&#8221;'> <?php echo $array[name]; ?></a></td>
  918.     <td class="column-name"><?php echo ($array[status])?"Active":"Hidden"; ?></td>
  919.     <td class="column-name"><a href="admin.php?page=contactdir-category&edit=<?php echo $array[id]; ?>">Edit</a> | <span class='delete'><a class='delete:the-list: submitdelete' href='admin.php?page=contactdir-category&delete=<?php echo $array[id]; ?>' onclick="if ( confirm('You are about to delete this category \'<?php echo $array[name]; ?>\'\n \'Cancel\' to stop, \'OK\' to delete.') ) { return true;}return false;">Delete</a></span></td>
  920.     </tr>
  921.     <?php } endif; ?>
  922.     </tbody>
  923.  
  924. </table>
  925.  
  926. <div class="tablenav">
  927.  
  928. <div class="alignleft actions">
  929. <select name="action2">
  930. <option value="" selected="selected">Bulk Actions</option>
  931. <option value="delete">Delete</option>
  932. </select>
  933. <input type="submit" value="Apply" name="doaction2" id="doaction2" class="button-secondary action" />
  934. </div>
  935. <br class="clear" />
  936. </div>
  937.  
  938. </form>
  939.  
  940.  
  941. </div>
  942. </div><!-- /col-right -->
  943.  
  944. <div id="col-left">
  945. <div class="col-wrap">
  946.  
  947.  
  948. <div class="form-wrap">
  949. <?php
  950. if($_GET[edit]) {
  951.     echo "<h3>Edit Category</h3>";
  952. } else {
  953.     echo "<h3>Add Category</h3>";
  954. }
  955. ?>
  956. <div id="ajax-response"></div>
  957. <form method="post" action="admin.php?page=contactdir-category" class="">
  958. <?php
  959.  
  960. if($_GET[edit]) {
  961.     echo "<input name=contactdir_cat_edit value='".$_GET[edit]."' type=hidden>";
  962.     $row = $wpdb->get_row("SELECT * FROM `$tb` WHERE `id` = '".$_GET[edit]."'",ARRAY_A);
  963. } else {
  964.     $row[status] = 1;
  965. }
  966. ?>
  967. <div class="form-field form-required">
  968.     <label for="contactdir_cat_name">Category Name</label>
  969.     <input name="contactdir_cat_name" id="contactdir_cat_name" type="text" value="<?php echo $row[name]; ?>" size="40" aria-required="true" />
  970. </div>
  971. <div class="form-field form-required">
  972.     <label for="contactdir_cat_status">Category Name</label>
  973.     <select id="contactdir_cat_status" name="contactdir_cat_status">
  974.         <option value="1">Active</option>
  975.         <option value="0" <?php if($row[status] == 0) echo "selected"; ?>>Hidden</option>
  976.     </select>
  977. </div>
  978.  
  979. <?php
  980. if($_GET[edit]) {
  981.     echo '<p class="submit"><input type="submit" class="button" name="submit" value="Edit Category" />';
  982.     echo "&nbsp;<a href='admin.php?page=contactdir-category'>Cancel Editing</a>";
  983. } else {
  984.     echo '<p class="submit"><input type="submit" class="button" name="submit" value="Add Category" />';
  985. }
  986. ?>
  987. </p>
  988. </form></div>
  989.  
  990.  
  991. </div>
  992. </div><!-- /col-left -->
  993.  
  994. </div><!-- /col-container -->
  995. </div><!-- /wrap -->
  996.  
  997.     <?php
  998.     ahlul_credit();
  999.     echo '</div>';
  1000. }
  1001.  
  1002. function csv2array($file,$include_table_header = TRUE,$sep = ";") {
  1003.     $row = 1;
  1004.     if (($handle = fopen($file, "r")) !== FALSE) {
  1005.         while (($data = fgetcsv($handle, 1000, $sep)) !== FALSE) {
  1006.             $num = count($data);
  1007.             $array[] = $data;
  1008.         }
  1009.         fclose($handle);
  1010.         if($include_table_header) $array = array_slice($array, 1);
  1011.     }
  1012.     return array("data"=>$array,"numfields"=>$num);
  1013. }
  1014.  
  1015. ?>