Exemple #1
0
function get_categories_and_products($parent_id)
{
    $href_string = "javascript:set_return('productcatalog')";
    $nodes = array();
    if ($parent_id == '' or empty($parent_id)) {
        $query = "select id, name , 'category' type from product_categories where (parent_id is null or parent_id='') and deleted=0";
        $query .= " union select id, name , 'product' type from product_templates where (category_id is null or category_id='') and deleted=0";
    } else {
        $query = "select id, name , 'category' type from product_categories where parent_id ='{$parent_id}' and deleted=0";
        $query .= " union select id, name , 'product' type from product_templates where category_id ='{$parent_id}' and deleted=0";
    }
    $result = $GLOBALS['db']->query($query);
    // fetchByAssoc has been changed in version 7 and it does encoding of the string data.
    // for the treeview we do not encoding as it messes up the display of the folder labels,
    // hence we pass false as an additional parameter
    while (($row = $GLOBALS['db']->fetchByAssoc($result, false)) != null) {
        $node = new Node($row['id'], $row['name']);
        $node->set_property("href", $href_string);
        $node->set_property("type", $row['type']);
        if ($row['type'] == 'product') {
            $node->expanded = false;
            $node->dynamic_load = false;
        } else {
            $node->expanded = false;
            $node->dynamic_load = true;
        }
        $nodes[] = $node;
    }
    return $nodes;
}
Exemple #2
0
function get_product_categories($parent_id, $open_nodes_ids = array())
{
    $href_string = "javascript:set_return('productcategories')";
    reset($open_nodes_ids);
    $nodes = array();
    if ($parent_id == '') {
        $query = "select * from product_categories where (parent_id is null or parent_id='') and deleted=0 order by list_order";
    } else {
        $query = "select * from product_categories where parent_id ='{$parent_id}' and deleted=0 order by list_order";
    }
    $result = $GLOBALS['db']->query($query);
    while (($row = $GLOBALS['db']->fetchByAssoc($result)) != null) {
        $node = new Node($row['id'], $row['name']);
        $node->set_property("href", $href_string);
        if (count($open_nodes_ids) > 0 and $row['id'] == current($open_nodes_ids)) {
            $node->expanded = true;
            $node->dynamic_load = false;
            $current_id = current($open_nodes_ids);
            array_shift($open_nodes_ids);
            $child_nodes = get_product_categories($current_id, $open_nodes_ids);
            //add all returned node to current node.
            foreach ($child_nodes as $child_node) {
                $node->add_node($child_node);
            }
        } else {
            $node->expanded = false;
            $node->dynamic_load = true;
        }
        $nodes[] = $node;
    }
    return $nodes;
}
Exemple #3
0
 function populateTree($nodes, &$parent)
 {
     foreach ($nodes as $node) {
         if (empty($node['label'])) {
             $node['label'] = $node['name'];
         }
         $yn = new Node($parent->id . '/' . $node['name'], $node['label']);
         if (!empty($node['action'])) {
             $yn->set_property('action', $node['action']);
         }
         $yn->set_property('href', 'javascript:void(0);');
         $yn->id = $parent->id . '/' . $node['name'];
         if (!empty($node['children'])) {
             $this->populateTree($node['children'], $yn);
         }
         $parent->add_node($yn);
     }
 }
 public function populateTree($nodes, &$parent)
 {
     foreach ($nodes as $node) {
         if (empty($node['label'])) {
             $node['label'] = $node['name'];
         }
         $yn = new Node($parent->id . '/' . $node['name'], $node['label']);
         if (!empty($node['action'])) {
             $yn->set_property('action', $node['action']);
         }
         $yn->set_property('href', 'javascript:void(0);');
         $yn->id = $parent->id . '/' . $node['name'];
         if (!empty($node['children'])) {
             $this->populateTree($node['children'], $yn);
         }
         // Sets backward compatibility flag into the node defs for use on the
         // client if needed
         if (!empty($node['bwc'])) {
             $yn->set_property('bwc', $node['bwc']);
         }
         $parent->add_node($yn);
     }
 }
Exemple #5
0
 public function get_test_nodes($href_string)
 {
     $nodes = array();
     $cat_node = new Node("1111", "1111");
     $cat_node->set_property("href", $href_string);
     // $cat_node->expanded = false;
     $cat_node->dynamic_load = false;
     $subcat_node = new Node("sub 1111", "sub 1111");
     $cat_node->add_node($subcat_node);
     $nodes[] = $cat_node;
     $cat_node = new Node("2222", "2222");
     $cat_node->set_property("href", $href_string);
     $cat_node->dynamic_load = false;
     $nodes[] = $cat_node;
     $cat_node = new Node("3333", "3333");
     $cat_node->set_property("href", $href_string);
     $cat_node->dynamic_load = false;
     $nodes[] = $cat_node;
     $cat_node = new Node("4444", "4444");
     $cat_node->set_property("href", $href_string);
     $cat_node->dynamic_load = true;
     $nodes[] = $cat_node;
     return $nodes;
 }
 /**
  * A Static method used to build the initial treeview when the page is first displayed
  *
  * @param String div_id - this div in which to display the tree
  * @return Tree - the tree that is built
  */
 function buildTreeView($div_id, $isAlive = true)
 {
     $tree = new Tree($div_id);
     $nodes = array();
     if ($isAlive) {
         $nodes = PackageManager::getCategories('');
     }
     foreach ($nodes as $arr_node) {
         $node = new Node($arr_node['id'], $arr_node['label']);
         $node->dynamicloadfunction = 'PackageManager.loadDataForNodeForPackage';
         $node->expanded = false;
         $node->dynamic_load = true;
         $node->set_property('href', "javascript:PackageManager.catClick('treeview');");
         $tree->add_node($node);
         $node->set_property('description', $arr_node['description']);
     }
     return $tree;
 }
Exemple #7
0
function get_documents($cat_id, $subcat_id, $href = true)
{
    $nodes = array();
    $href_string = "javascript:select_document('doctree')";
    $query = "select * from documents where deleted=0";
    if ($cat_id != 'null') {
        $query .= " and category_id='{$cat_id}'";
    } else {
        $query .= " and category_id is null";
    }
    if ($subcat_id != 'null') {
        $query .= " and subcategory_id='{$subcat_id}'";
    } else {
        $query .= " and subcategory_id is null";
    }
    $result = $GLOBALS['db']->query($query);
    $current_cat_id = null;
    while (($row = $GLOBALS['db']->fetchByAssoc($result)) != null) {
        $node = new Node($row['id'], $row['document_name']);
        if ($href) {
            $node->set_property("href", $href_string);
        }
        $node->expanded = true;
        $node->dynamic_load = false;
        $nodes[] = $node;
    }
    return $nodes;
}
            $root_node->set_property("href", $href_string);
        }
        $root_node->expanded = true;
        $tagstree->add_node($root_node);
    } else {
        $tagstree->set_param('moduleview', 'modal');
        //$nodes = get_tags_nodes_cached(null);
        //$nodes=get_tags_nodes(false,null);
        $nodes = get_tags_nodes(false, false, null);
        $root_node = new Node('All_Tags', $mod_strings['LBL_TAGS_ROOT_LABEL']);
        foreach ($nodes as $node) {
            $root_node->add_node($node);
        }
        $href_string = "javascript:handler:SUGAR.kb.modalClose('tagstree')";
        if ($root_node) {
            $root_node->set_property("href", $href_string);
        }
        $root_node->expanded = true;
        $tagstree->add_node($root_node);
    }
    //$tagstree->add_node($root_node);
    $response = $tagstree->generate_nodes_array();
} else {
    $response = 1;
}
if (!empty($response)) {
    echo $response;
    //$json = getJSONobj();
    //print $json->encode($response);
    //return the parameters
}
Exemple #9
0
function return_advanced_tab($focus, $json, $json_config)
{
    global $theme, $image_path, $app_list_strings, $mod_strings, $app_strings;
    $ss_adv = new Sugar_Smarty();
    $ss_adv->assign("MOD", $mod_strings);
    $ss_adv->assign("APP", $app_strings);
    //assign back values from last search, if it exists.
    //do not set any values if value has been set
    if (isset($_POST['clear_loaded'])) {
        $_POST['searchText'] = '';
        foreach ($_POST as $_key => $_val) {
            $ss_adv->assign($_key, '');
        }
    } else {
        foreach ($_POST as $_key => $_val) {
            $ss_adv->assign($_key, $_val);
        }
    }
    $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'FTSFormAdvanced', 'field_to_name_array' => array('id' => 'kbdoc_approver_id', 'name' => 'kbdoc_approver_name'));
    $ss_adv->assign('encoded_approver_popup_request_data', $json->encode($popup_request_data));
    $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'FTSFormAdvanced', 'field_to_name_array' => array('id' => 'kbarticle_author_id', 'name' => 'kbarticle_author_name'));
    $ss_adv->assign('encoded_author_popup_request_data', $json->encode($popup_request_data));
    $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'FTSFormAdvanced', 'field_to_name_array' => array('id' => 'tag_id', 'tag_name' => 'tag_name'));
    $ss_adv->assign('encoded_tags_popup_request_data', $json->encode($popup_request_data));
    $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'FTSFormAdvanced', 'field_to_name_array' => array('id' => 'team_id', 'name' => 'team_name'));
    $json = getJSONobj();
    $ss_adv->assign('encoded_team_popup_request_data', $json->encode($popup_request_data));
    $ss_adv->assign("PRINT_URL", "index.php?" . $GLOBALS['request_string']);
    $ss_adv->assign("ID", $focus->id);
    $ss_adv->assign("DOCUMENT_NAME", $focus->kbdocument_name);
    $ss_adv->assign("DESCRIPTION", $focus->description);
    $ss_adv->assign("ACTIVE_DATE", $focus->active_date);
    $ss_adv->assign("EXP_DATE", $focus->exp_date);
    $status_option = "<option value='' selected>" . $app_strings['LBL_NONE'] . "</option> ";
    if (isset($_POST['status_id'])) {
        $status_option .= get_select_options_with_id($app_list_strings['kbdocument_status_dom'], $_POST['status_id']);
        $ss_adv->assign("STATUS_OPTIONS", $status_option);
    } else {
        $status_option .= get_select_options_with_id($app_list_strings['kbdocument_status_dom'], '');
        $ss_adv->assign("STATUS_OPTIONS", $status_option);
    }
    if (isset($_POST['saved_search_select']) && !empty($_POST['saved_search_select'])) {
        $ss_adv->assign("SAVED_SEARCH_OPTIONS", getSavedSearchOptions($focus, $_POST['saved_search_select']));
        $savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . getSavedSearchOptions($focus, $_POST['saved_search_select'], true)));
    } else {
        $ss_adv->assign("SAVED_SEARCH_OPTIONS", getSavedSearchOptions($focus));
        $savedSearchSelects = $json->encode(array($GLOBALS['app_strings']['LBL_SAVED_SEARCH_SHORTCUT'] . '<br>' . getSavedSearchOptions($focus, '', true)));
    }
    $str = "<script>\n    YAHOO.util.Event.addListener(window, 'load', SUGAR.util.fillShortcuts, {$savedSearchSelects});\n    </script>";
    echo $str;
    if (isset($_POST['canned_search'])) {
        $ss_adv->assign("CANNED_SEARCH_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_canned_search'], $_POST['canned_search']));
    } else {
        $ss_adv->assign("CANNED_SEARCH_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_canned_search'], ''));
    }
    $a1_style = '';
    $x1_style = '';
    $a2_style = 'none';
    $x2_style = 'none';
    //set the expiration date filter if it exists.  Also set the style properties
    //that will determine whether to show or hide the supporting text boxes
    if (isset($_POST['active_date_filter'])) {
        $ss_adv->assign("ACTIVE_DATE_FILTER_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_date_filter_options'], $_POST['active_date_filter']));
        if ($_POST['active_date_filter'] == 'on' || $_POST['active_date_filter'] == 'before' || $_POST['active_date_filter'] == 'after') {
            $a1_style = '';
        } else {
            $a1_style = 'none';
        }
        if ($_POST['active_date_filter'] == 'between_dates') {
            $a2_style = '';
        }
    } else {
        $ss_adv->assign("ACTIVE_DATE_FILTER_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_date_filter_options'], ''));
    }
    //set the expiration date filter if it exists.  Also set the style properties
    //that will determine whether to show or hide the supporting text boxes
    if (isset($_POST['exp_date_filter'])) {
        $ss_adv->assign("EXP_DATE_FILTER_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_date_filter_options'], $_POST['exp_date_filter']));
        if ($_POST['exp_date_filter'] == 'on' || $_POST['exp_date_filter'] == 'before' || $_POST['exp_date_filter'] == 'after') {
            $x1_style = '';
        } else {
            $x1_style = 'none';
        }
        if ($_POST['exp_date_filter'] == 'between_dates') {
            $x2_style = '';
        }
    } else {
        $ss_adv->assign("EXP_DATE_FILTER_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_date_filter_options'], ''));
    }
    //set the style sheet properties for date filters
    $ss_adv->assign("A_DATE1_STYLE", $a1_style);
    $ss_adv->assign("X_DATE1_STYLE", $x1_style);
    $ss_adv->assign("A_DATE2_STYLE", $a2_style);
    $ss_adv->assign("X_DATE2_STYLE", $x2_style);
    $attach_name_style = 'none';
    $attach_mime_style = 'none';
    if (isset($_POST['attachments'])) {
        $ss_adv->assign("ATTACHMENT_SELECT_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_attachment_option_dom'], $_POST['attachments']));
        if ($_POST['attachments'] == 'mime') {
            $attach_mime_style = ' ';
        } else {
            if ($_POST['attachments'] == 'name') {
                $attach_name_style = ' ';
            }
        }
    } else {
        $ss_adv->assign("ATTACHMENT_SELECT_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_attachment_option_dom'], ''));
    }
    $ss_adv->assign("ATTACHMENT_NAME_STYLE", $attach_name_style);
    $ss_adv->assign("ATTACHMENT_MIME_STYLE", $attach_mime_style);
    if (!empty($focus->kbdoc_approver_id)) {
        $user = BeanFactory::getBean('Users', $focus->kbdoc_approver_id);
        $ss_adv->assign("KBDOC_APPROVER_NAME", $user->name);
        $ss_adv->assign("KBDOC_APPROVER_ID", $focus->kbdoc_approver_id);
    }
    global $timedate;
    $ss_adv->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
    $ss_adv->assign("USER_DATE_FORMAT", $timedate->get_user_date_format());
    $ss_adv->assign('JSON_CONFIG_JAVASCRIPT', $json_config->get_static_json_server());
    if (isset($_POST['frequency'])) {
        $ss_adv->assign("FRQ_VIEW_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_viewing_frequency_dom'], $_POST['frequency']));
    } else {
        $ss_adv->assign("FRQ_VIEW_OPTIONS", get_select_options_with_id($app_list_strings['kbdocument_viewing_frequency_dom'], ''));
    }
    if (isset($_POST['is_external_article'])) {
        if ($_POST['is_external_article']) {
            $ss_adv->assign('is_external_id', '1');
            $ss_adv->assign('is_external_checked', 'checked');
        } else {
            $ss_adv->assign('is_external_id', '0');
            $ss_adv->assign('is_external_checked', '');
        }
    }
    //create tree for tag selection modal
    $tag = BeanFactory::getBean('KBTags');
    $ss_adv->assign("TAG_NAME", $tag->tag_name);
    //tree header.
    $tagstree = new Tree('tagstree');
    $tagstree->set_param('module', 'KBTags');
    $tagstree->set_param('moduleview', 'modal');
    $nodes = get_tags_nodes(false, false, null);
    $root_node = new Node('All_Tags', $mod_strings['LBL_TAGS_ROOT_LABEL']);
    foreach ($nodes as $node) {
        $root_node->add_node($node);
    }
    $href_string = "javascript:handler:modalClose('tagstree')";
    if ($root_node) {
        $root_node->set_property("href", $href_string);
    }
    $root_node->expanded = true;
    $tagstree->add_node($root_node);
    $ss_adv->assign("TREEINSTANCE", $tagstree->generate_nodes_array());
    return $ss_adv->fetch("modules/KBDocuments/tpls/advancedTab.tpl");
}
/** create a new node for the tree widget
 * @param string user_id, primary key value of a valid sugar user.
 * @param string href script for the node.
 * @param boolean dynamic: allow dynamic loading of child node, defult is true
 * @param boolean force_direct:  force direct forecast for the node default false.
 * @param boolean top_level: is this the top level node, if yes add forecast type of node label, default false
 * @param boolean commit: commit of forecast is allowed from this node.
 */
function create_node($user_id, $href = true, $dynamic = true, $force_direct = false, $top_level = false, $commit = false)
{
    global $href_string;
    global $mod_strings;
    $user = new Common();
    $user->set_current_user($user_id);
    $user->setup();
    $rollup = true;
    $node_name = $user->my_name;
    if ($force_direct or count($user->my_direct_reports) == 0) {
        $rollup = false;
    }
    if ($top_level) {
        if ($rollup) {
            $node_name .= ' ' . $mod_strings['LBL_FMT_ROLLUP_FORECAST'];
        } else {
            $node_name .= ' ' . $mod_strings['LBL_FMT_DIRECT_FORECAST'];
        }
    }
    $node = new Node($user_id, $node_name);
    if ($href) {
        $node->set_property("href", $href_string);
    }
    $node->expanded = !$dynamic;
    $node->dynamic_load = $dynamic;
    //if user has downline set the forecast type property.
    if (!$rollup) {
        $node->set_property('forecasttype', 'Direct', true);
        $node->dynamic_load = false;
    } else {
        $node->set_property('forecasttype', 'Rollup', true);
    }
    $node->set_property('commit', $commit, true);
    return $node;
}
Exemple #11
0
function create_browse_node($id, $node_name, $tag_count = 0, $doc_count = 0)
{
    global $sugar_config, $currentModule, $current_language;
    $mod_strings = get_kbtag_strings();
    //_pp($mod_strings);
    //create the title to display when hovering over link
    $tag_LBL = $mod_strings['LBL_CHILD_TAGS_IN_TREE_HOVER'];
    $doc_LBL = $mod_strings['LBL_ARTICLES_IN_TREE_HOVER'];
    if ($tag_count == 1) {
        //use singular
        $tag_LBL = $mod_strings['LBL_CHILD_TAG_IN_TREE_HOVER'];
    }
    if ($doc_count == 1) {
        //use singular
        $doc_LBL = $mod_strings['LBL_ARTICLE_IN_TREE_HOVER'];
    }
    $title = $mod_strings['LBL_THIS_TAG_CONTAINS_TREE_HOVER'] . " {$tag_count} {$tag_LBL}, {$doc_count} {$doc_LBL}";
    $node_name = "<span title='{$title}'>{$node_name}</span>";
    $href = "javascript:node_click('kb_browse_tags','selected_directory_children', 'div', 'get_browse_documents')";
    //create node
    $node = new Node($id, $node_name);
    $node->set_property("href", $href);
    $node->expanded = false;
    //decide if the folder icon should display by sepcifying whether the node is dynamic or not.
    if ($tag_count == 0) {
        $node->dynamic_load = false;
    } else {
        $node->dynamic_load = true;
    }
    return $node;
}