/**
  * Uninstalls plugin
  */
 function uninstallPlugin()
 {
     global $CONFIG_DB_PREFIX;
     $db = DB::getSingleton();
     // DB extensions
     $db->query("DROP TABLE `{$CONFIG_DB_PREFIX}inTouch_touches`");
     $db->query("DROP TABLE `{$CONFIG_DB_PREFIX}inTouch_conds`");
 }
 /** DB statements to drop table within the TABR DB -- MUST USE PLUGIN NAME as table name
  */
 function uninstallPlugin()
 {
     global $CONFIG_DB_PREFIX;
     $db = DB::getSingleton();
     // DB extensions
     $db->query("DROP TABLE `{$CONFIG_DB_PREFIX}ContactChangeLogger`");
 }
 function editContactInterface(&$contact, $location)
 {
     if ($location != 'ownFieldset') {
         return "";
     }
     //if(!$_SESSION['user']->isAtLeast('manager'))
     //    return "";
     global $CONFIG_DB_PREFIX;
     $db = DB::getSingleton();
     // fetch dropdown
     $dropdown = $this->getDropdown($db, $contact->contact['id']);
     $db->query("SELECT partnerId,ouder1,ouder2,thuiswonend FROM " . $CONFIG_DB_PREFIX . "contact WHERE id = '" . $contact->contact['id'] . "'");
     $r = $db->next();
     $thuiswonend = false;
     if ($r['thuiswonend'] == 1) {
         $thuiswonend = true;
     }
     $content = '<fieldset class="edit-names">';
     $content .= '<legend>Relatives</legend>';
     $content .= '<div class="edit-line">';
     $content .= HTMLHelper::createDropdown("partner", 'Getrouwd met', $dropdown, $r['partnerId'], 'edit-input');
     $content .= HTMLHelper::createCheckbox("delpartner", 'Verwijder relatie', false, 'edit-input-checkbox');
     $content .= '</div>';
     $content .= '<hr />';
     $content .= '<div class="edit-line">';
     $content .= HTMLHelper::createDropdown("ouder1", 'Ouder 1', $dropdown, $r['ouder1'], 'edit-input');
     $content .= HTMLHelper::createCheckbox("thuiswonend", 'Thuiswonend', $thuiswonend, 'edit-input-checkbox');
     $content .= '</div>';
     $content .= '<div class="edit-line">';
     $content .= HTMLHelper::createDropdown("ouder2", 'Ouder 2', $dropdown, $r['ouder2'], 'edit-input');
     $content .= HTMLHelper::createCheckbox("delouders", 'Verwijder ouderrelaties', false, 'edit-input-checkbox');
     $content .= '</div>';
     return $content . '</fieldset>';
 }
 /**
  * Get the DB record from the user table if it esxists. Result is not cached because it is used rarely.
  * @return associative array of user or FALSE if not found
  */
 function getUserRecord()
 {
     $this->user = FALSE;
     // cache for getUserId()
     if (isset($this->contact['id'])) {
         $db = DB::getSingleton();
         $db->query('SELECT * FROM ' . TABLE_USERS . ' WHERE id = ' . $db->escape($this->contact['id']));
         if ($db->rowsAffected() == 1) {
             $r = $db->next();
             $this->user = intval($r['userid']);
             // cache for getUserId()
             return $r;
         }
     }
     return FALSE;
 }
 /**
  * Create search query
  *
  * init {@link $contactList}, and menu
  * @param search $search partial string to match
  * @param searchtype $searchtype [name|email|www|chat|phone|custom_?] Custom searches defined in config.php, shared with autocomplete.
  * @global array custom searchtypes defined in config.php
  * @global DB used for database access
  */
 function createQuery()
 {
     // create an empty default result - any better way to do this
     $sql = "SELECT * FROM " . TABLE_CONTACT . " AS contact WHERE id=-1";
     $db = DB::getSingleton();
     $admin = intval($_SESSION['user']->isAtLeast('admin'));
     $post = StringHelper::cleanGPC($_POST);
     // projects
     $props = array();
     $tbls = array();
     if (!empty($_POST['p-category'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p1';
         $props[] = 'c.id=p1.id AND p1.type="other" AND (p1.visibility = "visible" AND p1.label="Project Category" AND p1.value LIKE BINARY "%' . substr($db->escape($post['p-category']), 1, -1) . '%" )';
     }
     if (!empty($_POST['p-role'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p2';
         $props[] = 'c.id=p2.id AND p2.type="other" AND (p2.visibility = "visible" AND p2.label="Contract Role" AND    p2.value=' . $db->escape($post['p-role']) . ')';
     }
     if (!empty($_POST['p-company'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p3';
         $props[] = 'c.id=p3.id AND p3.type="other" AND (p3.visibility = "visible" AND p3.label="Applicant" AND        p3.value LIKE "%' . substr($db->escape($post['p-company']), 1, -1) . '%" )';
     }
     if (!empty($_POST['p-value'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p4';
         $props[] = 'c.id=p4.id AND p4.type="other" AND (p4.visibility = "visible" AND p4.label="SWARCO Value" AND     p4.value > ' . $db->escape($post['p-value']) . ')';
     }
     if (!empty($_POST['p-after'])) {
         $tbls[] = TABLE_DATES . ' AS d';
         $props[] = 'c.id=d.id AND (d.label="Completed" AND         d.value1 > ' . $db->escape($post['p-after']) . ')';
     }
     $propsel = implode(' AND ', $props);
     if (!empty($propsel)) {
         $tables = implode(', ', $tbls);
         $sel = "SELECT DISTINCT c.* FROM " . TABLE_CONTACT . " AS c, {$tables} WHERE ";
         $where = "c.xsltDisplayType='project' AND c.hidden=0 AND {$propsel} ORDER BY lastname";
         $sql = "{$sel} {$where}";
         //echo $sql;
         return $sql;
     }
     // project opportunity
     $props = array();
     $tbls = array();
     if (!empty($_POST['o-category'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p1';
         $props[] = 'c.id=p1.id AND p1.type="other" AND (p1.label="Project Category" AND p1.value LIKE BINARY "%' . substr($db->escape($post['o-category']), 1, -1) . '%" )';
     }
     if (!empty($_POST['o-role'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p2';
         $props[] = 'c.id=p2.id AND p2.type="other" AND (p2.label="Contract Role" AND    p2.value=' . $db->escape($post['o-role']) . ')';
     }
     if (!empty($_POST['o-company'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p3';
         $props[] = 'c.id=p3.id AND p3.type="other" AND (p3.label="Applicant" AND        p3.value LIKE "%' . substr($db->escape($post['o-company']), 1, -1) . '%" )';
     }
     if (!empty($_POST['o-value'])) {
         $tbls[] = TABLE_PROPERTIES . ' AS p4';
         $props[] = 'c.id=p4.id AND p4.type="other" AND (p4.label="SWARCO Value" AND     p4.value > ' . $db->escape($post['o-value']) . ')';
     }
     $propsel = implode(' AND ', $props);
     if (!empty($propsel)) {
         $tables = implode(', ', $tbls);
         $sel = "SELECT DISTINCT c.* FROM " . TABLE_CONTACT . " AS c, {$tables} WHERE ";
         $where = "c.xsltDisplayType='opportunity' AND c.hidden=0 AND {$propsel} ORDER BY lastname";
         $sql = "{$sel} {$where}";
         //echo $sql;
         return $sql;
     }
     // project candidate
     $props = array();
     if (!empty($_POST['c-position'])) {
         $props[] = 'd1.label=' . $db->escape($post['c-position']);
     }
     if (!empty($_POST['c-experience'])) {
         $props[] = 'd1.value1 < ' . $db->escape($post['c-experience']);
     }
     $propsel = implode(' AND ', $props);
     if (!empty($propsel)) {
         $sel = "SELECT DISTINCT c.* FROM " . TABLE_CONTACT . " AS c, " . TABLE_DATES . " AS d1 WHERE ";
         $where = "c.id=d1.id AND ({$propsel}) AND (d1.visibility = 'visible' OR {$admin}) AND (c.hidden = 0 OR {$admin}) AND c.xsltDisplayType='expertise' ORDER BY lastname";
         $sql = "{$sel} {$where}";
         //echo $sql;
         return $sql;
     }
     return $sql;
 }
 /** DB statements to drop table within the TABR DB -- MUST USE PLUGIN NAME as table name
  */
 function uninstallPlugin()
 {
     global $CONFIG_DB_PREFIX;
     $db = DB::getSingleton();
     // DB extensions
     $db->query("DROP TABLE IF EXISTS `{$CONFIG_DB_PREFIX}Relationships`");
 }