Passed
Push — master ( 1007d6...492b54 )
by Alxarafe
26:10
created

CategoriesIndexView::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) 2019       Alxarafe                    <[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
namespace Alixar\Views;
18
19
use Alxarafe\Helpers\Skin;
20
use Alixar\Helpers\Globals;
21
use Alixar\Base\Form;
22
use Alixar\Base\FormOther;
23
use Alixar\Helpers\DolUtils;
24
use Alixar\Base\Categorie;
25
26
class CategoriesIndexView extends \Alixar\Base\AlixarView
27
{
28
29
    public $backgroundImage;
30
    public $mainLoginBackgroundImage;
31
    public $useJMobile;
32
    public $focusElement;
33
    public $url;
34
    public $token;
35
    public $hideTopmenu;
36
    public $hideLeftmenu;
37
    public $optimizeSmallscreen;
38
    public $noMouseHover;
39
40
    public function __construct($ctrl)
41
    {
42
        parent::__construct($ctrl);
43
        $this->draw();
44
        $this->vars();
45
        Skin::setTemplate('categories_index');
46
    }
47
48
    public function vars()
49
    {
50
51
    }
52
53
    public function draw()
54
    {
55
        $catname = $this->ctrl->catname;
56
        $id = $this->ctrl->id;
57
58
// Load translation files required by the page
59
        Globals::$langs->load("categories");
60
61
        if (!Globals::$user->rights->categorie->lire) {
62
            accessforbidden();
63
        }
64
65
        $this->type = (DolUtils::GETPOST('type', 'aZ09') ? DolUtils::GETPOST('type', 'aZ09') : Categorie::TYPE_PRODUCT);
66
67
        if (is_numeric($this->type)) {
68
            $this->type = Categorie::$MAP_ID_TO_CODE[$this->type]; // For backward compatibility
69
        }
70
71
        /*
72
         * View
73
         */
74
75
        $categstatic = new Categorie();
76
        $form = new Form();
77
78
        if ($this->type == Categorie::TYPE_PRODUCT) {
79
            $this->title = Globals::$langs->trans("ProductsCategoriesArea");
80
            $this->typetext = 'product';
81
        } elseif ($this->type == Categorie::TYPE_SUPPLIER) {
82
            $this->title = Globals::$langs->trans("SuppliersCategoriesArea");
83
            $this->typetext = 'supplier';
84
        } elseif ($this->type == Categorie::TYPE_CUSTOMER) {
85
            $this->title = Globals::$langs->trans("CustomersCategoriesArea");
86
            $this->typetext = 'customer';
87
        } elseif ($this->type == Categorie::TYPE_MEMBER) {
88
            $this->title = Globals::$langs->trans("MembersCategoriesArea");
89
            $this->typetext = 'member';
90
        } elseif ($this->type == Categorie::TYPE_CONTACT) {
91
            $this->title = Globals::$langs->trans("ContactsCategoriesArea");
92
            $this->typetext = 'contact';
93
        } elseif ($this->type == Categorie::TYPE_ACCOUNT) {
94
            $this->title = Globals::$langs->trans("AccountsCategoriesArea");
95
            $this->typetext = 'bank_account';
96
        } elseif ($this->type == Categorie::TYPE_PROJECT) {
97
            $this->title = Globals::$langs->trans("ProjectsCategoriesArea");
98
            $this->typetext = 'project';
99
        } elseif ($this->type == Categorie::TYPE_USER) {
100
            $this->title = Globals::$langs->trans("UsersCategoriesArea");
101
            $this->typetext = 'user';
102
        } else {
103
            $this->title = Globals::$langs->trans("CategoriesArea");
104
            $this->typetext = 'unknown';
105
        }
106
107
        $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
108
        $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
109
110
        $this->llxHeader('', $this->title, '', '', 0, 0, $arrayofjs, $arrayofcss);
111
112
        $newcardbutton = '<a class="butActionNew" href="' . BASE_URI . '/categories/card.php?action=create&type=' . $this->type . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?type=' . $this->type) . '"><span class="valignmiddle">' . Globals::$langs->trans("NewCategory") . '</span>';
113
        $newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>';
114
        $newcardbutton .= '</a>';
115
116
        print DolUtils::load_fiche_titre($this->title, $newcardbutton);
117
118
//print '<table border="0" width="100%" class="notopnoleftnoright">';
119
//print '<tr><td valign="top" width="30%" class="notopnoleft">';
120
        print '<div class="fichecenter"><div class="fichethirdleft">';
121
122
123
        /*
124
         * Zone recherche produit/service
125
         */
126
        print '<form method="post" action="index.php?type=' . $this->type . '">';
127
        print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
128
        print '<input type="hidden" name="type" value="' . $this->type . '">';
129
130
131
        print '<table class="noborder nohover" width="100%">';
132
        print '<tr class="liste_titre">';
133
        print '<td colspan="3">' . Globals::$langs->trans("Search") . '</td>';
134
        print '</tr>';
135
        print '<tr class="oddeven"><td>';
136
        print Globals::$langs->trans("Name") . ':</td><td><input class="flat inputsearch" type="text" name="catname" value="' . $catname . '"/></td><td><input type="submit" class="button" value="' . Globals::$langs->trans("Search") . '"></td></tr>';
137
        /*
138
          // faire une rech dans une sous categorie uniquement
139
          print '<tr '.$bc[0].'><td>';
140
          print Globals::$langs->trans("SubCatOf").':</td><td>';
141
142
          print $form->select_all_categories('','subcatof');
143
          print '</td>';
144
          print '<td><input type="submit" class="button" value="'.Globals::$langs->trans ("Search").'"></td></tr>';
145
         */
146
147
        print '</table></form>';
148
149
150
//print '</td><td valign="top" width="70%">';
151
        print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
152
153
154
        /*
155
         * Categories found
156
         */
157
        if ($catname || $id > 0) {
158
            $cats = $categstatic->rechercher($id, $catname, $this->typetext);
159
160
            print '<table class="noborder" width="100%">';
161
            print '<tr class="liste_titre"><td colspan="2">' . Globals::$langs->trans("FoundCats") . '</td></tr>';
162
163
            foreach ($cats as $cat) {
164
                print "\t" . '<tr class="oddeven">' . "\n";
165
                print "\t\t<td>";
166
                $categstatic->id = $cat->id;
167
                $categstatic->ref = $cat->label;
168
                $categstatic->label = $cat->label;
169
                $categstatic->type = $cat->type;
170
                $categstatic->color = $cat->color;
171
                print '<span class="noborderoncategories" ' . ($categstatic->color ? ' style="background: #' . $categstatic->color . ';"' : ' style="background: #aaa"') . '>';
172
                print $categstatic->getNomUrl(1, '');
173
                print '</span>';
174
                print "</td>\n";
175
                print "\t\t<td>";
176
                print dolGetFirstLineOfText($cat->description);
177
                print "</td>\n";
178
                print "\t</tr>\n";
179
            }
180
            print "</table>";
181
        } else
182
            print '&nbsp;';
183
184
185
//print '</td></tr></table>';
186
        print '</div></div></div>';
187
188
        print '<div class="fichecenter"><br>';
189
190
191
// Charge tableau des categories
192
        $cate_arbo = $categstatic->get_full_arbo($this->typetext);
193
194
// Define fulltree array
195
        $fulltree = $cate_arbo;
196
197
// Define data (format for treeview)
198
        $data = array();
199
        $data[] = array('rowid' => 0, 'fk_menu' => -1, 'title' => "racine", 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
200
        foreach ($fulltree as $key => $val) {
201
            $categstatic->id = $val['id'];
202
            $categstatic->ref = $val['label'];
203
            $categstatic->color = $val['color'];
204
            $categstatic->type = $this->type;
205
            $li = $categstatic->getNomUrl(1, '', 60);
206
            $desc = dol_htmlcleanlastbr($val['description']);
207
208
            $data[] = array(
209
                'rowid' => $val['rowid'],
210
                'fk_menu' => $val['fk_parent'],
211
                'entry' => '<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories" ' . ($categstatic->color ? ' style="background: #' . $categstatic->color . ';"' : ' style="background: #aaa"') . '>' . $li . '</span></td>' .
212
                //'<td width="50%">'.dolGetFirstLineOfText($desc).'</td>'.
213
                '<td align="right" width="20px;"><a href="' . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $val['id'] . '&type=' . $this->type . '">' . img_view() . '</a></td>' .
214
                '</tr></table>'
215
            );
216
        }
217
218
219
//print_barre_liste('', 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, 0, '', 0, $newcardbutton, '', 0, 1, 1);
220
221
        print '<table class="liste nohover" width="100%">';
222
        print '<tr class="liste_titre"><td>' . Globals::$langs->trans("Categories") . '</td><td></td><td align="right">';
223
        if (!empty($conf->use_javascript_ajax)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by alxarafe
The variable $conf seems to be never defined.
Loading history...
224
            print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">' . img_picto('', 'object_category') . ' ' . Globals::$langs->trans("UndoExpandAll") . '</a> | <a class="notasortlink" href="#">' . img_picto('', 'object_category-expanded') . ' ' . Globals::$langs->trans("ExpandAll") . '</a></div>';
225
        }
226
        print '</td></tr>';
227
228
        $nbofentries = (count($data) - 1);
229
230
        if ($nbofentries > 0) {
231
            print '<tr class="pair"><td colspan="3">';
232
            tree_recur($data, $data[0], 0);
233
            print '</td></tr>';
234
        } else {
235
            print '<tr class="pair">';
236
            print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>' . img_picto_common('', 'treemenu/branchbottom.gif') . '</td>';
237
            print '<td valign="middle">';
238
            print Globals::$langs->trans("NoCategoryYet");
239
            print '</td>';
240
            print '<td>&nbsp;</td>';
241
            print '</table></td>';
242
            print '</tr>';
243
        }
244
245
        print "</table>";
246
247
        print '</div>';
248
249
// End of page
250
        llxFooter();
251
        $db->close();
0 ignored issues
show
Comprehensibility Best Practice introduced by alxarafe
The variable $db seems to be never defined.
Loading history...
252
    }
253
}
254