Хранилища Subversion ant

Редакция

Редакция 626 | Редакция 628 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
304 alex-w 1
<?php
2
 
3
/**
4
 *  
554 alex-w 5
 *  Codename: ant-ng - generator of sources.list for apt-distributives
304 alex-w 6
 *  http://alex-w.org.ru/p/antng/
7
 *
8
 *  Copyright (c) 2009 Alexander Wolf
9
 *  Dual licensed under the MIT and GNU LGPL licenses.
10
 *  http://alex-w.org.ru/p/antng/license
11
 *
12
 */
13
 
14
class Core {
308 alex-w 15
    protected $db       = NULL;
16
    protected $prefix   = NULL;
313 alex-w 17
    protected $secure   = NULL;    
359 alex-w 18
    protected $cookie   = NULL;
304 alex-w 19
 
463 alex-w 20
    /**
21
     * Конструктор класса Core - ядро генератора
22
     *
23
     * @author Alexander Wolf
24
     * @category Core
25
     *
26
     * @param string $database
27
     * @param string $prefix
28
     * @param object $secure
29
     * @param string $cookie
30
     */
368 alex-w 31
    public function __construct($database, $prefix, $secure, $cookie) {
308 alex-w 32
        $this->db       = $database;
33
        $this->prefix   = $prefix;
359 alex-w 34
        $this->secure   = $secure;
35
        $this->cookie   = $cookie;
307 alex-w 36
    }
37
 
463 alex-w 38
    /**
39
     * Получение данных о настройке
40
     *
41
     * @author Alexander Wolf
42
     * @category Core
43
     *
44
     * @param string $attr
45
     * @return array
46
     */
368 alex-w 47
    public function getOption($attr) {
308 alex-w 48
        $result = array();
315 alex-w 49
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
314 alex-w 50
        $rq =& $this->db->query($query);
308 alex-w 51
        if ($rq->numRows()!=0) {
52
            $rq->fetchInto($element);
53
            $result["ERR"] = 0;
54
            $result["OptValue"] = $element["optvalue"];
55
        } else {
56
            $result["ERR"] = 1;
57
            $result["ERRINFO"] = "Empty result";
58
        }
59
        return $result;
60
    }
61
 
463 alex-w 62
    /**
63
     * Установка данных о настройке
64
     *
65
     * @author Alexander Wolf
66
     * @category Core
67
     *
68
     * @param string $attr
69
     * @param string $value
70
     * @return array
71
     */
368 alex-w 72
    public function setOption($attr, $value) {
359 alex-w 73
        $result = array();
74
 
75
        if ($attr != "passwd") {
76
            $sValue = $this->secure->checkStr($value);
77
        } else {
78
            $sValue = $value;
79
        }
80
 
81
        $query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'";
82
        $rq =& $this->db->query($query);
83
        if (PEAR::isError($this->db)) {
84
            $result["ERR"] = 1;
85
            $result["ERRINFO"] = $this->db->getMessage();
86
        } else {
87
            $result["ERR"] = 0;
88
        }
89
 
90
        return $result;
91
    }
92
 
463 alex-w 93
    /**
94
     * Создание настройки
95
     *
96
     * @author Alexander Wolf
97
     * @category Core
98
     *
99
     * @param string $attr
100
     * @param string $value
101
     * @return array
102
     */
368 alex-w 103
    public function addOption($attr, $value) {
359 alex-w 104
        $result = array();
105
        $sValue = $this->secure->checkStr($value);
106
 
107
        $query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'";
108
        $rq =& $this->db->query($query);
109
        if (PEAR::isError($this->db)) {
110
            $result["ERR"] = 1;
111
            $result["ERRINFO"] = $this->db->getMessage();
112
        } else {
113
            $result["ERR"] = 0;
114
        }
115
 
116
        return $result;
117
    }
463 alex-w 118
 
119
    /**
467 alex-w 120
     * Получение и отображение списка дистрибутвов
463 alex-w 121
     *
122
     * @author Alexander Wolf
123
     * @category Core
124
     * @deprecated may be deprecated XXX
125
     *
126
     * @param string $name
127
     * @param string $heads
128
     * @param string $info
129
     * @param string $format
130
     * @return string
131
     */
393 alex-w 132
    public function showDistributionList($name, $heads = "", $info = "", $format = 'html') {
315 alex-w 133
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
317 alex-w 134
        $rq =& $this->db->query($query);
315 alex-w 135
        switch ($format) {
136
            case 'html':
394 alex-w 137
                $show  = "<fieldset><legend>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n";
390 alex-w 138
                $show .= "<option value=''>".$info."</option>\n";
315 alex-w 139
                while ($rq->fetchInto($element)) {
140
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
141
                }
317 alex-w 142
                $show .= "</select></fieldset>";
315 alex-w 143
                break;
144
            case 'json':
317 alex-w 145
                $show = '[{value:"",text:"'.$info.'"}';                
315 alex-w 146
                while ($rq->fetchInto($element)) {
147
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
148
                }
149
                $show .= ']';
150
                break;
504 alex-w 151
            case 'innerhtml':
152
                $show = "<select id='".$name."' name='".$name."'>\n";
153
                while ($rq->fetchInto($element)) {
154
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
155
                }
156
                $show .= "</select>";
157
                break;
506 alex-w 158
            case 'list':
159
                $show = "<ul>";
160
                while ($rq->fetchInto($element)) {
546 alex-w 161
                    $show .= "<li>[<a href='".$heads."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["dist_id"])."' class='edit'>править</a>][<a href='".$heads."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["dist_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)."</li>\n";
506 alex-w 162
                }
163
                $show .= "</ul>";
164
                break;
315 alex-w 165
        }
166
        return $show;
167
    }
168
 
463 alex-w 169
    /**
170
     * Получение названия дистрибутива
171
     *
172
     * @author Alexander Wolf
173
     * @category Core
174
     *
175
     * @param integer $distID
176
     * @return array
177
     */
368 alex-w 178
    public function getDistName($distID) {
315 alex-w 179
        $result = array();
180
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
181
        $rq =& $this->db->query($query);
182
        if (PEAR::isError($this->db)) {
183
            $result["ERR"] = 1;
184
            $result["ERRINFO"] = $this->db->getMessage();
185
        } else {
186
            $rq->fetchInto($element);
187
            $result["ERR"] = 0;
188
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
189
        }
190
 
191
        return $result;
192
    }
193
 
463 alex-w 194
    /**
195
     * Получение названия программы, ее версии и описания
196
     *
197
     * @author Alexander Wolf
198
     * @category Core
199
     *
200
     * @param string $attr
201
     * @return string
202
     */
383 alex-w 203
    public function getEngineAttr($attr = 'codename') {
204
        $cname = $this->getOption($attr);
382 alex-w 205
        return $this->secure->checkStr($cname["OptValue"],1);
381 alex-w 206
    }
207
 
463 alex-w 208
    /**
209
     * Получение и отображение списка версий дистрибутива
210
     *
211
     * @author Alexander Wolf
212
     * @category Core
213
     *
214
     * @param string $name
215
     * @param integer $distID
216
     * @param string $format
217
     * @return string
218
     */
509 alex-w 219
    public function showDistVersionsList($name, $distID, $format = 'html', $actor = '') {
316 alex-w 220
        $distname = $this->getDistName($distID);
509 alex-w 221
        if ($distID == 0) {
222
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ORDER BY d.dist_id,v.version ASC";
223
        } else {
224
            $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
225
        }
317 alex-w 226
        $rq =& $this->db->query($query);
315 alex-w 227
        switch ($format) {
228
            case 'html':
394 alex-w 229
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
230
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
315 alex-w 231
                while ($rq->fetchInto($element)) {
316 alex-w 232
                    $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["version"],1)." ".$this->secure->checkStr($element["vname"],1)."</option>\n";
315 alex-w 233
                }
317 alex-w 234
                $show .= "</select></fieldset>";
315 alex-w 235
                break;
236
            case 'json':
317 alex-w 237
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
315 alex-w 238
                while ($rq->fetchInto($element)) {
316 alex-w 239
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
315 alex-w 240
                }
241
                $show .= ']';
242
                break;
509 alex-w 243
            case 'list':
244
                $show = "<ul>\n";
245
                while ($rq->fetchInto($element)) {
545 alex-w 246
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)." ".$this->secure->checkStr($element["version"],1)." &#8220;<em>".$this->secure->checkStr($element["vname"],1)."</em>&#8221;</li>\n";
509 alex-w 247
                }
248
                $show .= "</ul>";
249
                break;
315 alex-w 250
        }
251
        return $show;
252
    }
253
 
463 alex-w 254
    /**
255
     * Получение и отображение списка секций основного (официального) репозитория
256
     *
257
     * @author Alexander Wolf
258
     * @category Core
259
     *
260
     * @param integer $version
261
     * @param string $format
262
     * @return string
263
     */
368 alex-w 264
    public function showBranchesList($version, $format = 'html') {
317 alex-w 265
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
266
        $rq =& $this->db->query($query);
267
        $rq->fetchInto($types);
268
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
269
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
270
        $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
271
        $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
627 alex-w 272
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."' ";
273
        $query .= "ORDER BY s.sect_id ASC";
317 alex-w 274
        $rq =& $this->db->query($query);
275
        switch ($format) {
276
            case 'html':
277
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
278
                while ($rq->fetchInto($element)) {
493 alex-w 279
                    $show .= "<div class='sections'><input type='checkbox' name='section[]' value='".$element["sect_id"]."'> ".$this->secure->checkStr($element["secname"],1)." &mdash; ".$this->secure->checkStr($element["sectinfo"],1)."</div>\n";
317 alex-w 280
                }
281
                $show .= "</fieldset>\n";
282
                break;
283
            case 'json':
284
                //TODO Доделать JSON-вывод списка секций основного репозитория
285
                break;
286
        }
318 alex-w 287
 
288
        return $show;
317 alex-w 289
    }
290
 
463 alex-w 291
    /**
292
     * Получение и отображение списка репозиториев
293
     *
294
     * @author Alexander Wolf
295
     * @category Core
296
     *
297
     * @param integer $version
298
     * @param integer $reptype
299
     * @param string $format
300
     * @return string
301
     */
368 alex-w 302
    public function showRepList($version, $reptype, $format = 'html') {
606 alex-w 303
        $query = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
304
        $rq =& $this->db->query($query);
305
        $rq->fetchInto($types);
317 alex-w 306
        $query = "SELECT * FROM ".$this->prefix."repository WHERE version='".$this->secure->checkInt($version)."' AND rtype_id='".$this->secure->checkInt($reptype)."'";
307
        $rq =& $this->db->query($query);
308
        switch ($format) {
309
            case 'html':
607 alex-w 310
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
311
                while ($rq->fetchInto($element)) {
320 alex-w 312
                    $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." &mdash; ".$this->secure->checkStr($element["repinfo"],1)."</div>\n";
317 alex-w 313
                }
314
                $show .= "</fieldset>\n";
315
                break;
316
            case 'json':
317
                //TODO Доделать JSON-вывод списка репозиториев
318
                break;
319
        }
318 alex-w 320
 
321
        return $show;
317 alex-w 322
    }
323
 
463 alex-w 324
    /**
325
     * Добавление поддержки нового apt-дистрибутива
326
     *
327
     * @author Alexander Wolf
328
     * @category Core
329
     *
330
     * @param string $distname
331
     * @param integer $disttype
332
     * @param string $distua
333
     * @param byte $distlogo
334
     * @return array
335
     */
514 alex-w 336
    public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) {
321 alex-w 337
        $result = array();
582 alex-w 338
        $sDName = $this->secure->checkStr($distname);
321 alex-w 339
        $sDType = $this->secure->checkInt($disttype);
582 alex-w 340
        $sDUAgt = $this->secure->checkStr($distua);
514 alex-w 341
        $sDLogo = $this->secure->checkInt($distlogo);
321 alex-w 342
 
343
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
344
        $rq =& $this->db->query($query);
345
        if (PEAR::isError($this->db)) {
346
            $result["ERR"] = 1;
347
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 348
        } else {            
321 alex-w 349
            $result["ERR"] = 0;
350
        }
351
 
352
        return $result;
353
    }
354
 
463 alex-w 355
    /**
514 alex-w 356
     * Обновление информации о дистрибутиве
357
     *
358
     * @author Alexander Wolf
359
     * @category Core
360
     *
361
     * @param integer $distID
362
     * @param string $distname
363
     * @param integer $disttype
364
     * @param string $distua
365
     * @param integer $distlogo
366
     * @return array
367
     */
538 alex-w 368
    public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo = 0) {
514 alex-w 369
        $result = array();
370
        $sDID   = $this->secure->checkInt($distID);
579 alex-w 371
        $sDName = $this->secure->checkStr($distname);
514 alex-w 372
        $sDType = $this->secure->checkInt($disttype);
579 alex-w 373
        $sDUAgt = $this->secure->checkStr($distua);
514 alex-w 374
        $sDLogo = $this->secure->checkInt($distlogo);
375
 
538 alex-w 376
        if ($sDLogo!=0) {
377
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
378
        } else {
379
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."' WHERE dist_id='".$sDID."'";
380
        }
514 alex-w 381
        $rq =& $this->db->query($query);
382
        if (PEAR::isError($this->db)) {
383
            $result["ERR"] = 1;
384
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 385
        } else {            
514 alex-w 386
            $result["ERR"] = 0;
387
        }
388
 
389
        return $result;
390
    }
391
 
392
    /**
393
     * Удаление информации о дистрибутиве
394
     *
395
     * @author Alexander Wolf
396
     * @category Core
397
     *
398
     * @param integer $distID
399
     * @return array
400
     */
401
    public function dropDistribution($distID) {
402
        $result = array();
403
        $sDID   = $this->secure->checkInt($distID);
404
 
405
        // Удаление дистрибутива
406
        $query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
407
        $rq =& $this->db->query($query);
408
        if (PEAR::isError($this->db)) {
409
            $result["ERR"] = 1;
410
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 411
        } else {            
514 alex-w 412
            $result["ERR"] = 0;
413
        }
414
 
415
        // Удаление версий дистрибутива
416
        $query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
417
        $rq =& $this->db->query($query);
418
        if (PEAR::isError($this->db)) {
419
            $result["ERR"] = 1;
420
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 421
        } else {            
514 alex-w 422
            $result["ERR"] = 0;
423
        }
424
 
425
        return $result;
426
    }
427
 
428
    /**
463 alex-w 429
     * Добавление поддержки новой версии apt-дистрибутива
430
     *
431
     * @author Alexander Wolf
432
     * @category Core
433
     *
434
     * @param integer $distID
435
     * @param integer $version
436
     * @param string $vname
437
     * @param integer $vcodename
438
     * @return array
439
     */
368 alex-w 440
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
356 alex-w 441
        $result = array();
463 alex-w 442
        $sDistID    = $this->secure->checkInt($distID);
582 alex-w 443
        $sDVersion  = $this->secure->checkStr($version);
444
        $sDVName    = $this->secure->checkStr($vname);
445
        $sDVCName   = $this->secure->checkStr($vcodename);
356 alex-w 446
 
447
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
448
        $rq =& $this->db->query($query);
449
        if (PEAR::isError($this->db)) {
450
            $result["ERR"] = 1;
451
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 452
        } else {            
356 alex-w 453
            $result["ERR"] = 0;
454
        }
455
 
456
        return $result;
457
    }
358 alex-w 458
 
463 alex-w 459
    /**
514 alex-w 460
     * Редактирование информации о версии дистрибутива
461
     *
462
     * @author Alexander Wolf
463
     * @category Core
464
     *
465
     * @param integer $versionID
466
     * @param string $version
467
     * @param string $vname
468
     * @param string $vcodename
469
     * @return array
470
     */
471
    public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") {
472
        $result = array();
473
        $sVersID    = $this->secure->checkInt($versionID);
516 alex-w 474
        $sDVersion  = $this->secure->checkStr($version,1);
475
        $sDVName    = $this->secure->checkStr($vname,1);
476
        $sDVCName   = $this->secure->checkStr($vcodename,1);
514 alex-w 477
 
478
        $query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
479
        $rq =& $this->db->query($query);
480
        if (PEAR::isError($this->db)) {
481
            $result["ERR"] = 1;
482
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 483
        } else {            
514 alex-w 484
            $result["ERR"] = 0;
485
        }
486
 
487
        return $result;
488
    }
489
 
490
    /**
491
     * Удаление информации о версии дистрибутива
492
     *
493
     * @author Alexander Wolf
494
     * @category Core
495
     *
496
     * @param integer $versionID
497
     * @return array
498
     */
499
    public function dropDistVersion($versionID) {
500
        $result = array();
501
        $sVersID    = $this->secure->checkInt($versionID);
502
 
503
        // Удаление версии дистрибутива
504
        $query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
505
        $rq =& $this->db->query($query);
506
        if (PEAR::isError($this->db)) {
507
            $result["ERR"] = 1;
508
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 509
        } else {            
514 alex-w 510
            $result["ERR"] = 0;
511
        }
512
 
513
        // Удаление репозиториев этой версии дистрибутива
514
        $query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
515
        $rq =& $this->db->query($query);
516
        if (PEAR::isError($this->db)) {
517
            $result["ERR"] = 1;
518
            $result["ERRINFO"] = $this->db->getMessage();
517 alex-w 519
        } else {            
514 alex-w 520
            $result["ERR"] = 0;
521
        }
522
 
523
        return $result;
524
    }
525
 
526
    /**
463 alex-w 527
     * Отображение типа дистрибутива
528
     *
529
     * @author Alexander Wolf
530
     * @category Core
531
     *
532
     * @param string $name
533
     * @param byte $type
534
     * @return string
535
     */
368 alex-w 536
    public function showDistTypeForm($name = "dtype",$type = 0) {
329 alex-w 537
        $query = "SELECT * FROM ".$this->prefix."dtype";
538
        $rq =& $this->db->query($query);
539
        $show = "<select name='".$name."' id='".$name."'>\n";
540
        while ($rq->fetchInto($element)) {
347 alex-w 541
            if ($element["type_id"] == $type) {
542
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 543
            } else {
347 alex-w 544
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 545
            }
546
        }
547
        $show .= "</select>";
548
 
549
        return $show;
550
    }
551
 
463 alex-w 552
    /**
553
     * Отображение формы создания и редактирования apt-дистрибутива
554
     *
555
     * @author Alexander Wolf
556
     * @category Core
557
     *
558
     * @param integer $distID
559
     * @return string
560
     */
511 alex-w 561
    public function showDistributionForm($distID = 0, $info = '') {
329 alex-w 562
        $sDistID = $this->secure->checkInt($distID);
511 alex-w 563
        $sInfo = $this->secure->checkStr($info, 1);
564
        if ($sInfo == "") {
565
            $sInfo = "Дистрибутив";
566
        }
329 alex-w 567
        if ($sDistID != 0) {
568
            // Режим редактирования
569
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
570
            $rq =& $this->db->query($query);
571
            $rq->fetchInto($element);
572
        }
573
 
574
        if ($element["distlogo"] == 1) {
380 alex-w 575
            $image = "<img src='./img/d/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."' title='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."'>";
329 alex-w 576
        } else {
380 alex-w 577
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
329 alex-w 578
        }
579
 
511 alex-w 580
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
350 alex-w 581
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
582
        $show .= "<div class='inputbox'><label for='dua'>UA дистрибутива:</label> <input type='text' name='dua' id='dua' value='".$this->secure->checkStr($element["distua"],1)."'></div>\n";
518 alex-w 583
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["disttype"])."</div>\n";
348 alex-w 584
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
329 alex-w 585
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
350 alex-w 586
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
329 alex-w 587
 
588
        return $show;
589
    }
590
 
358 alex-w 591
    // sourses.list
423 alex-w 592
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
593
       //TODO Написать генератор sources.list       
358 alex-w 594
    }
522 alex-w 595
 
463 alex-w 596
    /**
522 alex-w 597
     * Показывает список секций
598
     *
599
     * @author Alexander Wolf
600
     * @category Core
601
     *
602
     * @param string $name
603
     * @param string $actor
561 alex-w 604
     * @param string $format
522 alex-w 605
     * @return string
606
     */
560 alex-w 607
    public function showSectionsList($name, $actor, $format = 'html') {
608
        switch($format) {
609
            case 'html':
561 alex-w 610
                $query = "SELECT * FROM ".$this->prefix."section";
611
                $rq =& $this->db->query($query);
560 alex-w 612
                $show = "<ul>\n";
613
                while ($rq->fetchInto($element)) {
614
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sect_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sect_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["secname"],1)."</li>\n";
615
                }
616
                $show .= "</ul>";
617
                break;
618
            case 'innerhtml':
619
                $show = "";
561 alex-w 620
                $repID = $this->secure->checkInt($actor);
621
                if ($repID==0) {
622
                    $query = "SELECT * FROM ".$this->prefix."section";
623
                    $rq =& $this->db->query($query);
624
                    while ($rq->fetchInto($element)) {
567 alex-w 625
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 626
                    }
627
                } else {
628
                    $query = "SELECT * FROM ".$this->prefix."section s JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$repID'";
629
                    $rq =& $this->db->query($query);
630
                    while ($rq->fetchInto($element)) {
567 alex-w 631
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."' checked>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 632
                    }
633
                    $query = "SELECT s.* FROM ".$this->prefix."section s WHERE s.sect_id NOT IN (SELECT sect_id FROM ".$this->prefix."sect2rep WHERE rep_id='$repID')";
563 alex-w 634
                    $rq =& $this->db->query($query);
561 alex-w 635
                    while ($rq->fetchInto($element)) {
567 alex-w 636
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 637
                    }
638
                }
639
 
560 alex-w 640
                break;
522 alex-w 641
        }
642
 
643
        return $show;
644
    }
645
 
523 alex-w 646
    /**
647
     * Вывод формы редактирования/добавления секций
648
     *
649
     * @author Alexander Wolf
650
     * @category Core
651
     *
652
     * @param integer $sectionID
653
     * @param string $info
654
     * @return string
655
     */
656
    public function showSectionsForm($sectionID = 0, $info = "") {
522 alex-w 657
        $sSectID = $this->secure->checkInt($sectionID);
658
        $sInfo = $this->secure->checkStr($info, 1);
659
        if ($sInfo == "") {
660
            $sInfo = "Секция";
661
        }
662
        if ($sSectID != 0) {
663
            // Режим редактирования
664
            $query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
665
            $rq =& $this->db->query($query);
666
            $rq->fetchInto($element);
667
        }
668
 
669
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
670
        $show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
671
        $show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
672
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
673
 
674
        return $show;
675
    }
676
 
677
    /**
523 alex-w 678
     * Обновление информации о секции
679
     *
680
     * @author Alexander Wolf
681
     * @category Core
682
     *
683
     * @param integer $sectionID
684
     * @param string $sname
685
     * @param string $sinfo
686
     * @return array
687
     */
688
    public function updateSection($sectionID, $sname, $sinfo = "") {
689
        $result = array();
690
        $sSectID    = $this->secure->checkInt($sectionID);
579 alex-w 691
        $sSName     = $this->secure->checkStr($sname);
692
        $sSInfo     = $this->secure->checkStr($sinfo);
523 alex-w 693
 
694
        $query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
695
        $rq =& $this->db->query($query);
696
        if (PEAR::isError($this->db)) {
697
            $result["ERR"] = 1;
698
            $result["ERRINFO"] = $this->db->getMessage();
699
        } else {
700
            $result["ERR"] = 0;
701
        }
702
 
703
        return $result;
704
    }
705
 
706
    /**
707
     * Удаление информации о секции
708
     *
709
     * @author Alexander Wolf
710
     * @category Core
711
     *
712
     * @param integer $sectionID
713
     * @return array
714
     */
715
    public function dropSection($sectionID) {
716
        $result = array();
717
        $sSectID    = $this->secure->checkInt($sectionID);
718
 
719
        // Удаление секции
720
        $query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
721
        $rq =& $this->db->query($query);
722
        if (PEAR::isError($this->db)) {
723
            $result["ERR"] = 1;
724
            $result["ERRINFO"] = $this->db->getMessage();
725
        } else {
726
            $result["ERR"] = 0;
727
        }
728
 
729
        return $result;
730
    }
731
 
732
    /**
733
     * Добавление новой секции
734
     *
735
     * @author Alexander Wolf
736
     * @category Core
737
     *
738
     * @param string $sname
739
     * @param string $sinfo
740
     * @return array
741
     */
742
    public function addSection($sname, $sinfo = "") {
743
        $result = array();
582 alex-w 744
        $sSName = $this->secure->checkStr($sname);
745
        $sSInfo = $this->secure->checkStr($sinfo);
523 alex-w 746
 
747
        $query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
748
        $rq =& $this->db->query($query);
749
        if (PEAR::isError($this->db)) {
750
            $result["ERR"] = 1;
751
            $result["ERRINFO"] = $this->db->getMessage();
752
        } else {
753
            $result["ERR"] = 0;
754
        }
755
 
756
        return $result;
757
    }
758
 
759
    /**
568 alex-w 760
     * Вывод списка поддерживаемых архитектур
761
     *
762
     * @author Alexander Wolf
763
     * @category Core
764
     *
765
     * @param string $name
766
     * @param string $actor
767
     * @param string $format
768
     * @return string
769
     */
770
    public function showArchList($name, $actor, $format = 'list') {
771
        switch($format) {
772
            case 'list':
773
                $query = "SELECT * FROM ".$this->prefix."arch";
774
                $rq =& $this->db->query($query);
775
                $show = "<ul>\n";
776
                while ($rq->fetchInto($element)) {
777
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["arch_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["arch_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["arch"],1)."</li>\n";
778
                }
779
                $show .= "</ul>";
780
                break;
781
            case 'innerhtml':
782
                $show = "";
783
                $repID = $this->secure->checkInt($actor);
614 alex-w 784
                if ($repID==0) {
568 alex-w 785
                    $query = "SELECT * FROM ".$this->prefix."arch";
786
                    $rq =& $this->db->query($query);
787
                    while ($rq->fetchInto($element)) {
788
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
789
                    }
790
                } else {
791
                    $query = "SELECT * FROM ".$this->prefix."arch a JOIN ".$this->prefix."arch2rep r ON a.arch_id=r.arch_id WHERE r.rep_id='$repID'";
792
                    $rq =& $this->db->query($query);
793
                    while ($rq->fetchInto($element)) {
794
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."' checked>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
795
                    }
796
                    $query = "SELECT a.* FROM ".$this->prefix."arch a WHERE a.arch_id NOT IN (SELECT arch_id FROM ".$this->prefix."arch2rep WHERE rep_id='$repID')";
797
                    $rq =& $this->db->query($query);
610 alex-w 798
                    if ($rq->numRows()>0) {
799
                        while ($rq->fetchInto($element)) {
800
                            $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
801
                        }
568 alex-w 802
                    }
803
                }
804
                break;
805
        }
806
        return $show;
807
    }
808
 
809
    /**
810
     * Добавление новой архитектуры
811
     *
812
     * @author Alexander Wolf
813
     * @category Core
814
     *
815
     * @param string $arch
816
     * @return array
817
     */
818
    public function addArch($arch) {
819
        $result = array();
582 alex-w 820
        $sArch = $this->secure->checkStr($arch);
568 alex-w 821
 
822
        $query = "INSERT INTO ".$this->prefix."arch SET arch='".$sArch."'";
823
        $rq =& $this->db->query($query);
824
        if (PEAR::isError($this->db)) {
825
            $result["ERR"] = 1;
826
            $result["ERRINFO"] = $this->db->getMessage();
827
        } else {
828
            $result["ERR"] = 0;
829
        }
830
 
831
        return $result;
832
    }
833
 
834
    /**
835
     * Удаление информации об архитектуре
836
     *
837
     * @author Alexander Wolf
838
     * @category Core
839
     *
840
     * @param integer $archID
841
     * @return array
842
     */
843
    public function dropArch($archID) {
844
        $result = array();
845
        $sArchID    = $this->secure->checkInt($archID);
846
 
847
        // Удаление архитектуры
848
        $query = "DELETE FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
849
        $rq =& $this->db->query($query);
850
        if (PEAR::isError($this->db)) {
851
            $result["ERR"] = 1;
852
            $result["ERRINFO"] = $this->db->getMessage();
853
        } else {
854
            $result["ERR"] = 0;
855
        }
856
 
857
        // Удаление архитектуры из списка репозиториев
858
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE arch_id='".$sArchID."'";
859
        $rq =& $this->db->query($query);
860
        if (PEAR::isError($this->db)) {
861
            $result["ERR"] = 1;
862
            $result["ERRINFO"] = $this->db->getMessage();
863
        } else {
864
            $result["ERR"] = 0;
865
        }
866
        return $result;
867
    }
868
 
869
    /**
870
     * Обновление информации об архитектуре
871
     *
872
     * @author Alexander Wolf
873
     * @category Core
874
     *
875
     * @param integer $archID
876
     * @param string $arch
877
     * @return array
878
     */
879
    public function updateArch($archID, $arch) {
880
        $result = array();
881
        $sArchID    = $this->secure->checkInt($archID);
579 alex-w 882
        $sArch      = $this->secure->checkStr($arch);
568 alex-w 883
 
884
        $query = "UPDATE ".$this->prefix."arch SET arch='".$sArch."' WHERE arch_id='".$sArchID."'";
885
        $rq =& $this->db->query($query);
886
        if (PEAR::isError($this->db)) {
887
            $result["ERR"] = 1;
888
            $result["ERRINFO"] = $this->db->getMessage();
889
        } else {
890
            $result["ERR"] = 0;
891
        }
892
 
893
        return $result;
894
    }
895
 
896
    /**
897
     * Вывод формы редактирования/добавления архитектур
898
     *
899
     * @author Alexander Wolf
900
     * @category Core
901
     *
902
     * @param integer $archID
903
     * @param string $info
904
     * @return string
905
     */
906
    public function showArchForm($archID = 0, $info = "") {
907
        $sArchID = $this->secure->checkInt($archID);
908
        $sInfo = $this->secure->checkStr($info, 1);
909
        if ($sInfo == "") {
910
            $sInfo = "Архитектура";
911
        }
912
        if ($sArchID != 0) {
913
            // Режим редактирования
914
            $query = "SELECT * FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
915
            $rq =& $this->db->query($query);
916
            $rq->fetchInto($element);
917
        }
918
 
919
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
920
        $show .= "<div class='inputbox'><label for='arch'>Архитектура:</label> <input type='text' name='arch' id='arch' value='".$this->secure->checkStr($element["arch"],1)."'></div>\n";
921
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
922
 
923
        return $show;
924
    }
925
 
926
    /**
570 alex-w 927
     * Вывод списка схем репозиториев
928
     *
929
     * @author Alexander Wolf
930
     * @category Core
931
     *
932
     * @param string $name
933
     * @param string $actor
934
     * @param string $format
935
     * @return string
936
     */
937
    public function showSchemeList($name, $actor, $format = 'list') {
938
        switch($format) {
939
            case 'list':
940
                $query = "SELECT * FROM ".$this->prefix."repscheme";
941
                $rq =& $this->db->query($query);
942
                $show = "<ul>\n";
943
                while ($rq->fetchInto($element)) {
944
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["scheme_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["scheme_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["scheme"],1)."</li>\n";
945
                }
946
                $show .= "</ul>";
947
                break;
948
            case 'innerhtml':
611 alex-w 949
                $schemeID = $this->secure->checkInt($actor);
570 alex-w 950
                $query = "SELECT * FROM ".$this->prefix."repscheme";
951
                $rq =& $this->db->query($query);
952
                $show = "<select name='".$name."' id='".$name."'>\n";
953
                while ($rq->fetchInto($element)) {
611 alex-w 954
                    if ($element["scheme_id"]==$schemeID) {
570 alex-w 955
                        $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."' selected>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
956
                    } else {
611 alex-w 957
                        $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."'>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
570 alex-w 958
                    }
959
                }
960
                $show .= "</select>";
961
                break;
962
        }
963
        return $show;
964
    }
965
 
966
    /**
967
     * Добавление новой схемы репозитория
968
     *
969
     * @author Alexander Wolf
970
     * @category Core
971
     *
972
     * @param string $scheme
973
     * @return array
974
     */
975
    public function addScheme($scheme) {
976
        $result = array();
582 alex-w 977
        $sScheme = $this->secure->checkStr($scheme);
570 alex-w 978
 
979
        $query = "INSERT INTO ".$this->prefix."repscheme SET scheme='".$sScheme."'";
980
        $rq =& $this->db->query($query);
981
        if (PEAR::isError($this->db)) {
982
            $result["ERR"] = 1;
983
            $result["ERRINFO"] = $this->db->getMessage();
984
        } else {
985
            $result["ERR"] = 0;
986
        }
987
 
988
        return $result;
989
    }
990
 
991
    /**
992
     * Удаление информации о схеме репозитория
993
     *
994
     * @author Alexander Wolf
995
     * @category Core
996
     *
997
     * @param integer $schemeID
998
     * @return array
999
     */
1000
    public function dropScheme($schemeID) {
1001
        $result = array();
1002
        $sSchemeID    = $this->secure->checkInt($schemeID);
1003
 
1004
        // Удаление схемы
1005
        $query = "DELETE FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1006
        $rq =& $this->db->query($query);
1007
        if (PEAR::isError($this->db)) {
1008
            $result["ERR"] = 1;
1009
            $result["ERRINFO"] = $this->db->getMessage();
1010
        } else {
1011
            $result["ERR"] = 0;
1012
        }
1013
 
1014
        return $result;
1015
    }
1016
 
1017
    /**
1018
     * Обновление информации о схеме репозитория
1019
     *
1020
     * @author Alexander Wolf
1021
     * @category Core
1022
     *
1023
     * @param integer $schemeID
1024
     * @param string $info
1025
     * @return array
1026
     */
1027
    public function updateScheme($schemeID, $info) {
1028
        $result = array();
1029
        $sSchemeID    = $this->secure->checkInt($schemeID);
579 alex-w 1030
        $sScheme      = $this->secure->checkStr($info);
570 alex-w 1031
 
1032
        $query = "UPDATE ".$this->prefix."repscheme SET scheme='".$sScheme."' WHERE scheme_id='".$sSchemeID."'";
1033
        $rq =& $this->db->query($query);
1034
        if (PEAR::isError($this->db)) {
1035
            $result["ERR"] = 1;
1036
            $result["ERRINFO"] = $this->db->getMessage();
1037
        } else {
1038
            $result["ERR"] = 0;
1039
        }
1040
 
1041
        return $result;
1042
    }
1043
 
1044
    /**
1045
     * Вывод формы редактирования/добавления схем репозиториев
1046
     *
1047
     * @author Alexander Wolf
1048
     * @category Core
1049
     *
1050
     * @param integer $schemeID
1051
     * @param string $info
1052
     * @return string
1053
     */
1054
    public function showSchemeForm($schemeID = 0, $info = "") {
1055
        $sSchemeID = $this->secure->checkInt($schemeID);
1056
        $sInfo = $this->secure->checkStr($info, 1);
1057
        if ($sInfo == "") {
1058
            $sInfo = "Схема репозитория";
1059
        }
571 alex-w 1060
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
570 alex-w 1061
        if ($sSchemeID != 0) {
1062
            // Режим редактирования
1063
            $query = "SELECT * FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1064
            $rq =& $this->db->query($query);
573 alex-w 1065
            $rq->fetchInto($element);            
1066
        }
571 alex-w 1067
 
573 alex-w 1068
        $show .= "<div class='inputbox'><label for='scheme'>Схема репозитория:</label> <input type='text' name='scheme' id='scheme' value='".$this->secure->checkStr($element["scheme"],1)."'></div>\n";
570 alex-w 1069
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1070
 
1071
        return $show;
1072
    }
1073
 
1074
    /**
574 alex-w 1075
     * Вывод списка протоколов
1076
     *
1077
     * @author Alexander Wolf
1078
     * @category Core
1079
     *
1080
     * @param string $name
1081
     * @param string $actor
1082
     * @param string $format
1083
     * @return string
1084
     */
1085
    public function showProtoList($name, $actor, $format = 'list') {
1086
        switch($format) {
1087
            case 'list':
1088
                $query = "SELECT * FROM ".$this->prefix."protos";
1089
                $rq =& $this->db->query($query);
1090
                $show = "<ul>\n";
1091
                while ($rq->fetchInto($element)) {
1092
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["proto_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["proto_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["proto"],1)."</li>\n";
1093
                }
1094
                $show .= "</ul>";
1095
                break;
1096
            case 'innerhtml':
1097
                $protoID = $this->secure->checkInt($actor);
1098
                $query = "SELECT * FROM ".$this->prefix."protos";
1099
                $rq =& $this->db->query($query);
1100
                $show = "<select name='".$name."' id='".$name."'>\n";
1101
                while ($rq->fetchInto($element)) {
1102
                    if ($element["proto_id"]==$protoID) {
1103
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."' selected>".$this->secure->checkStr($element["proto"],1)."</option>\n";
1104
                    } else {
580 alex-w 1105
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."'>".$this->secure->checkStr($element["proto"],1)."</option>\n";
574 alex-w 1106
                    }
1107
                }
1108
                $show .= "</select>";
1109
                break;
1110
        }
1111
        return $show;
1112
    }
1113
 
1114
    /**
1115
     * Добавление нового протокола
1116
     *
1117
     * @author Alexander Wolf
1118
     * @category Core
1119
     *
1120
     * @param string $proto
1121
     * @return array
1122
     */
1123
    public function addProto($proto) {
1124
        $result = array();
582 alex-w 1125
        $sProto = $this->secure->checkStr($proto);
574 alex-w 1126
 
1127
        $query = "INSERT INTO ".$this->prefix."protos SET proto='".$sProto."'";
1128
        $rq =& $this->db->query($query);
1129
        if (PEAR::isError($this->db)) {
1130
            $result["ERR"] = 1;
1131
            $result["ERRINFO"] = $this->db->getMessage();
1132
        } else {
1133
            $result["ERR"] = 0;
1134
        }
1135
 
1136
        return $result;
1137
    }
1138
 
1139
    /**
1140
     * Удаление информации о протоколе
1141
     *
1142
     * @author Alexander Wolf
1143
     * @category Core
1144
     *
1145
     * @param integer $protoID
1146
     * @return array
1147
     */
1148
    public function dropProto($protoID) {
1149
        $result = array();
1150
        $sProtoID    = $this->secure->checkInt($protoID);
1151
 
1152
        // Удаление протокола
1153
        $query = "DELETE FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1154
        $rq =& $this->db->query($query);
1155
        if (PEAR::isError($this->db)) {
1156
            $result["ERR"] = 1;
1157
            $result["ERRINFO"] = $this->db->getMessage();
1158
        } else {
1159
            $result["ERR"] = 0;
1160
        }
1161
 
1162
        return $result;
1163
    }
1164
 
1165
    /**
1166
     * Обновление информации о протоколе
1167
     *
1168
     * @author Alexander Wolf
1169
     * @category Core
1170
     *
1171
     * @param integer $protoID
1172
     * @param string $info
1173
     * @return array
1174
     */
1175
    public function updateProto($protoID, $info) {
1176
        $result = array();
1177
        $sProtoID    = $this->secure->checkInt($protoID);
579 alex-w 1178
        $sProto      = $this->secure->checkStr($info);
574 alex-w 1179
 
1180
        $query = "UPDATE ".$this->prefix."protos SET proto='".$sProto."' WHERE proto_id='".$sProtoID."'";
1181
        $rq =& $this->db->query($query);
1182
        if (PEAR::isError($this->db)) {
1183
            $result["ERR"] = 1;
1184
            $result["ERRINFO"] = $this->db->getMessage();
1185
        } else {
1186
            $result["ERR"] = 0;
1187
        }
1188
 
1189
        return $result;
1190
    }
1191
 
1192
    /**
1193
     * Вывод формы редактирования/добавления протоколов
1194
     *
1195
     * @author Alexander Wolf
1196
     * @category Core
1197
     *
1198
     * @param integer $protoID
1199
     * @param string $info
1200
     * @return string
1201
     */
1202
    public function showProtoForm($protoID = 0, $info = "") {
1203
        $sProtoID = $this->secure->checkInt($protoID);
1204
        $sInfo = $this->secure->checkStr($info, 1);
1205
        if ($sInfo == "") {
1206
            $sInfo = "Протокол доступа";
1207
        }
1208
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1209
        if ($sProtoID != 0) {
1210
            // Режим редактирования
1211
            $query = "SELECT * FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1212
            $rq =& $this->db->query($query);
1213
            $rq->fetchInto($element);
1214
        }
1215
 
1216
        $show .= "<div class='inputbox'><label for='proto'>Протокол доступа:</label> <input type='text' name='proto' id='proto' value='".$this->secure->checkStr($element["proto"],1)."'></div>\n";
1217
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1218
 
1219
        return $show;
1220
    }
1221
 
1222
    /**
582 alex-w 1223
     * Вывод списка хостов
1224
     *
1225
     * @author Alexander Wolf
1226
     * @category Core
1227
     *
1228
     * @param string $name
1229
     * @param string $actor
1230
     * @param string $format
1231
     * @return string
1232
     */
1233
    public function showHostsList($name, $actor, $format = 'list') {
1234
        switch($format) {
1235
            case 'list':
1236
                $query = "SELECT * FROM ".$this->prefix."rephost";
1237
                $rq =& $this->db->query($query);
1238
                $show = "<ul>\n";
1239
                while ($rq->fetchInto($element)) {
1240
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["rhost_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["rhost_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["rhost"],1)."</li>\n";
1241
                }
1242
                $show .= "</ul>";
1243
                break;
1244
            case 'innerhtml':
1245
                $hostID = $this->secure->checkInt($actor);
1246
                $query = "SELECT * FROM ".$this->prefix."rephost";
1247
                $rq =& $this->db->query($query);
1248
                $show = "<select name='".$name."' id='".$name."'>\n";
1249
                while ($rq->fetchInto($element)) {
1250
                    if ($element["rhost_id"]==$hostID) {
1251
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."' selected>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1252
                    } else {
1253
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."'>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1254
                    }
1255
                }
1256
                $show .= "</select>";
1257
                break;
1258
        }
1259
        return $show;
1260
    }
1261
 
1262
    /**
1263
     * Добавление нового хоста
1264
     *
1265
     * @author Alexander Wolf
1266
     * @category Core
1267
     *
1268
     * @param string $host
1269
     * @return array
1270
     */
1271
    public function addHost($host) {
1272
        $result = array();
1273
        $sHost = $this->secure->checkStr($host);
1274
 
586 alex-w 1275
        $query = "INSERT INTO ".$this->prefix."rephost SET rhost='".$sHost."'";
582 alex-w 1276
        $rq =& $this->db->query($query);
1277
        if (PEAR::isError($this->db)) {
1278
            $result["ERR"] = 1;
1279
            $result["ERRINFO"] = $this->db->getMessage();
1280
        } else {
1281
            $result["ERR"] = 0;
1282
        }
1283
 
1284
        return $result;
1285
    }
1286
 
1287
    /**
1288
     * Удаление информации о хосте
1289
     *
1290
     * @author Alexander Wolf
1291
     * @category Core
1292
     *
1293
     * @param integer $hostID
1294
     * @return array
1295
     */
1296
    public function dropHost($hostID) {
1297
        $result = array();
1298
        $sHostID    = $this->secure->checkInt($hostID);
1299
 
1300
        // Удаление хоста
1301
        $query = "DELETE FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1302
        $rq =& $this->db->query($query);
1303
        if (PEAR::isError($this->db)) {
1304
            $result["ERR"] = 1;
1305
            $result["ERRINFO"] = $this->db->getMessage();
1306
        } else {
1307
            $result["ERR"] = 0;
1308
        }
1309
 
1310
        return $result;
1311
    }
1312
 
1313
    /**
1314
     * Обновление информации о хосте
1315
     *
1316
     * @author Alexander Wolf
1317
     * @category Core
1318
     *
1319
     * @param integer $hostID
1320
     * @param string $info
1321
     * @return array
1322
     */
1323
    public function updateHost($hostID, $info) {
1324
        $result = array();
1325
        $sHostID    = $this->secure->checkInt($hostID);
1326
        $sHost      = $this->secure->checkStr($info);
1327
 
1328
        $query = "UPDATE ".$this->prefix."rephost SET rhost='".$sHost."' WHERE rhost_id='".$sHostID."'";
1329
        $rq =& $this->db->query($query);
1330
        if (PEAR::isError($this->db)) {
1331
            $result["ERR"] = 1;
1332
            $result["ERRINFO"] = $this->db->getMessage();
1333
        } else {
1334
            $result["ERR"] = 0;
1335
        }
1336
 
1337
        return $result;
1338
    }
1339
 
1340
    /**
1341
     * Вывод формы редактирования/добавления хостов
1342
     *
1343
     * @author Alexander Wolf
1344
     * @category Core
1345
     *
1346
     * @param integer $hostID
1347
     * @param string $info
1348
     * @return string
1349
     */
1350
    public function showHostForm($hostID = 0, $info = "") {
1351
        $sHostID = $this->secure->checkInt($hostID);
1352
        $sInfo = $this->secure->checkStr($info, 1);
1353
        if ($sInfo == "") {
1354
            $sInfo = "Хост репозитория";
1355
        }
1356
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1357
        if ($sHostID != 0) {
1358
            // Режим редактирования
1359
            $query = "SELECT * FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1360
            $rq =& $this->db->query($query);
1361
            $rq->fetchInto($element);
1362
        }
1363
 
1364
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> <input type='text' name='rhost' id='rhost' value='".$this->secure->checkStr($element["rhost"],1)."'></div>\n";
1365
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1366
 
1367
        return $show;
1368
    }
1369
 
1370
    /**
589 alex-w 1371
     * Вывод списка корневых папок
1372
     *
1373
     * @author Alexander Wolf
1374
     * @category Core
1375
     *
1376
     * @param string $name
1377
     * @param string $actor
1378
     * @param string $format
1379
     * @return string
1380
     */
1381
    public function showFoldersList($name, $actor, $format = 'list') {
1382
        switch($format) {
1383
            case 'list':
1384
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1385
                $rq =& $this->db->query($query);
1386
                $show = "<ul>\n";
1387
                while ($rq->fetchInto($element)) {
1388
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["rfolder_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["rfolder_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["rfolder"],1)."</li>\n";
1389
                }
1390
                $show .= "</ul>";
1391
                break;
1392
            case 'innerhtml':
1393
                $folderID = $this->secure->checkInt($actor);
1394
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1395
                $rq =& $this->db->query($query);
1396
                $show = "<select name='".$name."' id='".$name."'>\n";
1397
                while ($rq->fetchInto($element)) {
1398
                    if ($element["rfolder_id"]==$folderID) {
1399
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."' selected>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1400
                    } else {
1401
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."'>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1402
                    }
1403
                }
1404
                $show .= "</select>";
1405
                break;
1406
        }
1407
        return $show;
1408
    }
1409
 
1410
    /**
1411
     * Добавление нового корневого каталога
1412
     *
1413
     * @author Alexander Wolf
1414
     * @category Core
1415
     *
1416
     * @param string $flder
1417
     * @return array
1418
     */
1419
    public function addFolder($folder) {
1420
        $result = array();
1421
        $sFolder = $this->secure->checkStr($folder);
1422
 
1423
        $query = "INSERT INTO ".$this->prefix."repfolder SET rfolder='".$sFolder."'";
1424
        $rq =& $this->db->query($query);
1425
        if (PEAR::isError($this->db)) {
1426
            $result["ERR"] = 1;
1427
            $result["ERRINFO"] = $this->db->getMessage();
1428
        } else {
1429
            $result["ERR"] = 0;
1430
        }
1431
 
1432
        return $result;
1433
    }
1434
 
1435
    /**
1436
     * Удаление информации о корневой папке
1437
     *
1438
     * @author Alexander Wolf
1439
     * @category Core
1440
     *
1441
     * @param integer $folderID
1442
     * @return array
1443
     */
1444
    public function dropFolder($folderID) {
1445
        $result = array();
1446
        $sFolderID    = $this->secure->checkInt($folderID);
1447
 
1448
        // Удаление корневой папки
1449
        $query = "DELETE FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1450
        $rq =& $this->db->query($query);
1451
        if (PEAR::isError($this->db)) {
1452
            $result["ERR"] = 1;
1453
            $result["ERRINFO"] = $this->db->getMessage();
1454
        } else {
1455
            $result["ERR"] = 0;
1456
        }
1457
 
1458
        return $result;
1459
    }
1460
 
1461
    /**
1462
     * Обновление информации о корневой папки
1463
     *
1464
     * @author Alexander Wolf
1465
     * @category Core
1466
     *
1467
     * @param integer $folderID
1468
     * @param string $info
1469
     * @return array
1470
     */
1471
    public function updateFolder($folderID, $info) {
1472
        $result = array();
1473
        $sFolderID    = $this->secure->checkInt($folderID);
1474
        $sFolder      = $this->secure->checkStr($info);
1475
 
1476
        $query = "UPDATE ".$this->prefix."repfolder SET rfolder='".$sFolder."' WHERE rfolder_id='".$sFolderID."'";
1477
        $rq =& $this->db->query($query);
1478
        if (PEAR::isError($this->db)) {
1479
            $result["ERR"] = 1;
1480
            $result["ERRINFO"] = $this->db->getMessage();
1481
        } else {
1482
            $result["ERR"] = 0;
1483
        }
1484
 
1485
        return $result;
1486
    }
1487
 
1488
    /**
1489
     * Вывод формы редактирования/добавления корневых папок
1490
     *
1491
     * @author Alexander Wolf
1492
     * @category Core
1493
     *
1494
     * @param integer $folderID
1495
     * @param string $info
1496
     * @return string
1497
     */
1498
    public function showFolderForm($folderID = 0, $info = "") {
1499
        $sFolderID = $this->secure->checkInt($folderID);
1500
        $sInfo = $this->secure->checkStr($info, 1);
1501
        if ($sInfo == "") {
1502
            $sInfo = "Корневая папка";
1503
        }
1504
        if ($sFolderID != 0) {
1505
            // Режим редактирования
1506
            $query = "SELECT * FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1507
            $rq =& $this->db->query($query);
1508
            $rq->fetchInto($element);
1509
        }
1510
 
1511
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1512
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> <input type='text' name='rfolder' id='rfolder' value='".$this->secure->checkStr($element["rfolder"],1)."'></div>\n";
1513
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1514
 
1515
        return $show;
1516
    }
1517
 
1518
    /**
539 alex-w 1519
     * Показывает список подписей
1520
     *
1521
     * @author Alexander Wolf
1522
     * @category Core
1523
     *
1524
     * @param string $name
1525
     * @param string $actor
596 alex-w 1526
     * @param string $format
539 alex-w 1527
     * @return string
1528
     */
594 alex-w 1529
    public function showSignsList($name, $actor, $format = 'list') {
539 alex-w 1530
        $query = "SELECT * FROM ".$this->prefix."signs";
1531
        $rq =& $this->db->query($query);
594 alex-w 1532
        switch ($format) {
1533
            case 'list':
1534
                $show = "<ul>\n";
1535
                while ($rq->fetchInto($element)) {
1536
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sign_id"]."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sign_id"]."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["sname"],1)."</li>\n";
1537
                }
1538
                $show .= "</ul>";
1539
                break;
1540
            case 'innerhtml':
1541
                $signID = $this->secure->checkInt($actor);
1542
                $show  = "<select name='".$name."' id='".$name."'>\n";
1543
                $show .= "<option value='0'>Подписи нет</option>\n";
1544
                while ($rq->fetchInto($element)) {
1545
                    if ($element["sign_id"]==$signID) {
1546
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."' selected>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1547
                    } else {
1548
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."'>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1549
                    }
1550
                }
1551
                $show .= "</select>\n";
1552
                break;
539 alex-w 1553
        }
1554
 
1555
        return $show;
1556
    }
1557
 
1558
    /**
1559
     * Вывод формы редактирования/добавления подписей
1560
     *
1561
     * @author Alexander Wolf
1562
     * @category Core
1563
     *
1564
     * @param integer $sectionID
1565
     * @param string $info
1566
     * @return string
1567
     */
1568
    public function showSignsForm($signID = 0, $info = "") {
1569
        $sSignID = $this->secure->checkInt($signID);
1570
        $sInfo = $this->secure->checkStr($info, 1);
1571
        if ($sInfo == "") {
1572
            $sInfo = "Подписи";
1573
        }
1574
        if ($sSignID != 0) {
1575
            // Режим редактирования
1576
            $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1577
            $rq =& $this->db->query($query);
1578
            $rq->fetchInto($element);
1579
        }
1580
 
1581
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1582
        $show .= "<div class='inputbox'><label for='sname'>Название подписи:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["sname"],1)."'></div>\n";
1583
        $show .= "<div class='inputbox'><label for='sinfo'>Описание подписи:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sinfo"],1)."'></div>\n";
1584
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1585
 
1586
        return $show;
1587
    }
1588
 
1589
    /**
1590
     * Обновление информации о секции
1591
     *
1592
     * @author Alexander Wolf
1593
     * @category Core
1594
     *
1595
     * @param integer $sectionID
1596
     * @param string $sname
1597
     * @param string $sinfo
1598
     * @return array
1599
     */
1600
    public function updateSign($signID, $sname, $sinfo = "") {
1601
        $result = array();
1602
        $sSignID    = $this->secure->checkInt($signID);
579 alex-w 1603
        $sSName     = $this->secure->checkStr($sname);
1604
        $sSInfo     = $this->secure->checkStr($sinfo);
539 alex-w 1605
 
1606
        $query = "UPDATE ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."' WHERE sign_id='".$sSignID."'";
1607
        $rq =& $this->db->query($query);
1608
        if (PEAR::isError($this->db)) {
1609
            $result["ERR"] = 1;
1610
            $result["ERRINFO"] = $this->db->getMessage();
1611
        } else {
1612
            $result["ERR"] = 0;
1613
        }
1614
 
1615
        return $result;
1616
    }
1617
 
1618
    /**
1619
     * Удаление информации о подписи
1620
     *
1621
     * @author Alexander Wolf
1622
     * @category Core
1623
     *
1624
     * @param integer $sectionID
1625
     * @return array
1626
     */
540 alex-w 1627
    public function dropSign($signID) {
539 alex-w 1628
        $result = array();
1629
        $sSignID    = $this->secure->checkInt($signID);
1630
 
1631
        // Удаление подписи
1632
        $query = "DELETE FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1633
        $rq =& $this->db->query($query);
1634
        if (PEAR::isError($this->db)) {
1635
            $result["ERR"] = 1;
1636
            $result["ERRINFO"] = $this->db->getMessage();
1637
        } else {
1638
            $result["ERR"] = 0;
1639
        }
1640
 
1641
        return $result;
1642
    }
1643
 
1644
    /**
540 alex-w 1645
     * Добавление новой подписи
539 alex-w 1646
     *
1647
     * @author Alexander Wolf
1648
     * @category Core
1649
     *
1650
     * @param string $sname
1651
     * @param string $sinfo
1652
     * @return array
1653
     */
540 alex-w 1654
    public function addSign($sname, $sinfo = "") {
539 alex-w 1655
        $result = array();
582 alex-w 1656
        $sSName = $this->secure->checkStr($sname);
1657
        $sSInfo = $this->secure->checkStr($sinfo);
539 alex-w 1658
 
540 alex-w 1659
        $query = "INSERT INTO ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."'";
539 alex-w 1660
        $rq =& $this->db->query($query);
1661
        if (PEAR::isError($this->db)) {
1662
            $result["ERR"] = 1;
1663
            $result["ERRINFO"] = $this->db->getMessage();
1664
        } else {
1665
            $result["ERR"] = 0;
1666
        }
1667
 
1668
        return $result;
1669
    }
540 alex-w 1670
 
539 alex-w 1671
    /**
463 alex-w 1672
     * Проверка пароля (из формы авторизации)
1673
     *
1674
     * @author Alexander Wolf
1675
     * @category Core
1676
     *
1677
     * @param string $word
1678
     * @return array
1679
     */
368 alex-w 1680
    public function checkSign($word) {
359 alex-w 1681
        $result = array();
1682
 
1683
        $sHash = $this->secure->encryptStr($word);
1684
        $pwd   = $this->getOption("passwd");
1685
        if ($sHash == $pwd["OptValue"]) {
1686
            $result["ERR"] = 0;
1687
            $result["Location"] = "manager.php";
1688
            setcookie($this->cookie, $sHash);
1689
        } else {
1690
            $result["ERR"] = 1;
1691
            $result["ERRINFO"] = "Password not valid";
368 alex-w 1692
            $result["Location"] = "manager.php?error=1";
359 alex-w 1693
        }
1694
 
1695
        return $result;
358 alex-w 1696
    }
357 alex-w 1697
 
463 alex-w 1698
    /**
1699
     * Проверка пароля (из cookies)
1700
     *
1701
     * @author Alexander Wolf
1702
     * @category Core
1703
     *
1704
     * @param string $hash
1705
     * @return array
1706
     */
368 alex-w 1707
    public function checkCookieSign($hash) {
359 alex-w 1708
        $result = array();
1709
 
1710
        $pwd = $this->getOption("passwd");
1711
        if ($hash == $pwd["OptValue"]) {
1712
            $result["ERR"] = 0;
1713
        } else {
1714
            $result["ERR"] = 1;
1715
            $result["ERRINFO"] = "Hash not valid";
368 alex-w 1716
            $result["Location"] = "manager.php";
359 alex-w 1717
        }
1718
 
1719
        return $result;
1720
    }
1721
 
463 alex-w 1722
    /**
1723
     * Форма ввода пароля
1724
     *
1725
     * @author Alexander Wolf
1726
     * @category Core
1727
     *
1728
     * @return string
1729
     */
368 alex-w 1730
    public function showSigninForm() {
425 alex-w 1731
        $show  = "<div id='regform'>";
1732
        $show .= "<form action='process.php' method='post'>\n";
368 alex-w 1733
        $show .= "<fieldset><legend>Пароль</legend>\n";
1734
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
427 alex-w 1735
        $show .= "<input type='password' name='word' value=''>\n";
368 alex-w 1736
        $show .= "<input type='submit' value=' Войти '>\n";
425 alex-w 1737
        $show .= "</fieldset>\n</form></div>\n";
368 alex-w 1738
 
1739
        return $show;
1740
    }
1741
 
463 alex-w 1742
    /**
1743
     * Обновление пароля
1744
     *
1745
     * @author Alexander Wolf
1746
     * @category Core
1747
     *
1748
     * @param string $word1
1749
     * @param string $word2
1750
     * @return array
1751
     */
368 alex-w 1752
    public function updatePassword($word1, $word2) {
359 alex-w 1753
        $result = array();
1754
 
1755
        if ($word1 == $word2) {
1756
            $sWord = $this->secure->encryptStr($word1);
1757
            $r = $this->setOption("passwd", $sWord);
1758
            $result = $r;
1759
        } else {
1760
            $result["ERR"] = 1;
1761
            $result["ERRINFO"] = "Passwords is mismatch";
1762
        }
1763
 
1764
        return $result;
1765
    }
1766
 
504 alex-w 1767
    /**
509 alex-w 1768
     * Отображение формы создания и редактирования версии apt-дистрибутива
504 alex-w 1769
     *
1770
     * @author Alexander Wolf
1771
     * @category Core
1772
     *
1773
     * @param string $name
1774
     * @param string $actor
1775
     * @param integer $versionID
1776
     * @return string
1777
     */
511 alex-w 1778
    public function showDistVersionsForm($versionID = 0, $info = '') {
509 alex-w 1779
        $sVersionID = $this->secure->checkInt($versionID);
511 alex-w 1780
        $sInfo = $this->secure->checkStr($info, 1);
1781
        if ($sInfo == "") {
1782
            $sInfo = "Версия дистрибутива";
1783
        }
509 alex-w 1784
        if ($sVersionID != 0) {
1785
            // Режим редактирования
556 alex-w 1786
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$sVersionID."'";
497 alex-w 1787
            $rq =& $this->db->query($query);
1788
            $rq->fetchInto($element);
509 alex-w 1789
        }
1790
 
511 alex-w 1791
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
510 alex-w 1792
        if ($sVersionID != 0) {
1793
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
1794
        } else {
1795
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
1796
        }
509 alex-w 1797
        $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
1798
        $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
1799
        $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
1800
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
495 alex-w 1801
 
504 alex-w 1802
        return $show;
509 alex-w 1803
    }    
504 alex-w 1804
 
520 alex-w 1805
    /**
1806
     * Парсер схемы адреса репозитория
1807
     * FIXME Возможно не потребуется
1808
     *
1809
     * @author Alexander Wolf
1810
     * @category Core
1811
     *
1812
     * @param string $repstring
1813
     * @return integer
1814
     */
1815
    public function repositoryParser($repstring) {
1816
        $tokens = array();
1817
        $sections = array();
1818
        $tokens = split(" ",$repstring);
1819
 
1820
        if ($tokens[0] == "deb") {
1821
            // debian/ubuntu репозиторий "type proto://host/folder distr sections"
1822
            $url = parse_url($tokens[1]);
1823
            $distr  = $tokens[2];
1824
 
1825
            for($i=3;$i<count($tokens);$i++) {
1826
                $sections[] = $tokens[$i];
1827
            }
1828
        } else {
1829
            // altlinux репозиторий "type [sign] proto://host/folder base repname"
1830
            if (stripos($tokens[1],"]")!=0) {
1831
                $sign = $tokens[1];
1832
                $url = parse_url($tokens[2]);
1833
                $base = $tokens[3];
1834
                $repname = $tokens[4];
1835
            } else {
1836
                $url = parse_url($tokens[1]);
1837
                $base = $tokens[2];
1838
                $repname = $tokens[3];
1839
            }
1840
        }
1841
 
1842
        $proto      = $url["scheme"]."://";
1843
        $addr       = $url["host"];
1844
        if ($url["port"]!="") {
1845
            $addr .= ":".$url["port"];
1846
        }
1847
        $path       = $url["path"];
1848
 
1849
        return 0;
1850
    }
1851
 
539 alex-w 1852
    /**
1853
     * Выгрузка картинок логотипов дистрибутивов
1854
     *
1855
     * @author Alexander Wolf
1856
     * @category Core
1857
     *
1858
     * @param string $path
1859
     * @param string $dist
1860
     * @param array $datafile
1861
     * @return integer
1862
     */
535 alex-w 1863
    public function uploadPicture($path, $dist, $datafile) {
1864
        $folder   = $path.$dist."-orig.png";
1865
        $folderN  = $path.$dist.".png";
1866
        $folderEM = $path.$dist."-em.png";
1867
 
1868
        $distlogo = 0;
1869
        if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
1870
            chmod($folder, 0644);
1871
            list($width, $height) = GetImageSize($folder);
1872
            $percent = 32/$height;
1873
            $newwidth = $width * $percent;
1874
            $newheight = $height * $percent;
1875
 
1876
            $output = ImageCreateTrueColor($newwidth, $newheight);
1877
            $source = ImageCreateFromPNG($folder);
1878
 
1879
            ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1880
            ImagePNG($output, $folderEM);
1881
 
1882
            $percent = 15/$height;
1883
            $newwidth = $width * $percent;
1884
            $newheight = $height * $percent;
1885
 
1886
            $output = ImageCreateTrueColor($newwidth, $newheight);
1887
 
1888
            ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1889
            ImagePNG($output, $folderN);
1890
 
1891
            unlink($folder);
1892
            $distlogo = 1;
1893
        }
1894
        return $distlogo;
1895
    }
547 alex-w 1896
 
1897
    /**
1898
     * Показ списка репозиториев
1899
     *
1900
     * @author Alexander Wolf
1901
     * @category Core
1902
     *
1903
     * @param string $name
1904
     * @param string $actor
1905
     * @param string $format
1906
     * @return string
1907
     */
548 alex-w 1908
    public function showRepositoriesList($name, $actor, $format = 'list') {
617 alex-w 1909
        $query  = "SELECT r.*,rt.*,CONCAT(v.version,' ',v.vname) AS fullname FROM ".$this->prefix."repository r ";
548 alex-w 1910
        $query .= "JOIN ".$this->prefix."rtype rt ON rt.rtype_id=r.rtype_id ";
615 alex-w 1911
        $query .= "JOIN ".$this->prefix."version v ON v.version_id=r.version";
548 alex-w 1912
        $rq =& $this->db->query($query);
1913
        $show = "<ul>";
1914
        while ($rq->fetchInto($element)) {
617 alex-w 1915
            $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["rep_id"])."' class='edit'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["rep_id"])."' class='delete'>удалить</a>] ".$this->secure->checkStr($element["repname"],1)." (".$this->secure->checkStr($element["fullname"],1)." &mdash; ".$this->secure->checkStr($element["rtype"],1).")</li>\n";
548 alex-w 1916
        }
1917
        $show .= "</ul>";
547 alex-w 1918
        return $show;
1919
    }
1920
 
1921
    /**
558 alex-w 1922
     * Вывод списка типов репозиториев
1923
     *
1924
     * @author Alexander Wolf
1925
     * @category Core
1926
     *
1927
     * @param integer $reptype
1928
     * @param string $name
1929
     * @return string
1930
     */
1931
    public function showRepType($reptype = 0, $name = "") {
1932
        $sRT = $this->secure->checkInt($reptype);
1933
        $sNM = $this->secure->checkStr($name,1);
559 alex-w 1934
        $query = "SELECT * FROM ".$this->prefix."rtype";
558 alex-w 1935
        $rq =& $this->db->query($query);
1936
        $show = "<select name='".$sNM."' id='".$sNM."'>\n";
1937
        while ($rq->fetchInto($element)) {
1938
            if ($element["rtype_id"]==$sRT) {
1939
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."' selected>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
1940
            } else {
1941
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."'>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
1942
            }
1943
        }
1944
        $show .= "</select>";
1945
 
1946
        return $show;
1947
    }
1948
 
623 alex-w 1949
    /**
1950
     * Вывод списка версий дистрибутивов
1951
     *
1952
     * @author Alexander Wolf
1953
     * @category Core
1954
     *
1955
     * @param string $name
1956
     * @param integer $versionID
1957
     * @return string
1958
     */
591 alex-w 1959
    public function showVDList($name, $versionID = 0) {
592 alex-w 1960
        $query  = "SELECT v.version_id, CONCAT(d.distname, ' ', v.version, ' ', v.vname) AS fullname FROM ".$this->prefix."version v ";
591 alex-w 1961
        $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id";
1962
        $rq =& $this->db->query($query);
1963
        $show = "<select name='".$name."' id='".$name."'>\n";
1964
        while ($rq->fetchInto($element)) {
592 alex-w 1965
            if ($element["version_id"]==$versionID) {
1966
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."' selected>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
1967
            } else {
1968
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
1969
            }
591 alex-w 1970
        }
1971
        $show .= "</select>";
1972
        return $show;
1973
    }
1974
 
558 alex-w 1975
    /**
547 alex-w 1976
     * Форма создания/редактирвоания репозиториев
1977
     *
1978
     * @author Alexander Wolf
1979
     * @category Core
1980
     *
1981
     * @param integer $repID
1982
     * @param string $info
1983
     * @param string $reptype
1984
     * @return string
1985
     */
594 alex-w 1986
    public function showRepositoriesForm($repID = 0, $info = "") {
556 alex-w 1987
        $sRepID = $this->secure->checkInt($repID);
594 alex-w 1988
        $sInfo  = $this->secure->checkStr($info, 1);        
556 alex-w 1989
        if ($sInfo == "") {
1990
            $sInfo = "Репозиторий";
1991
        }
1992
        if ($sRepID != 0) {
1993
            // Режим редактирования
591 alex-w 1994
            $query  = "SELECT r.*,v.*,d.dist_id,dt.type FROM ".$this->prefix."repository r ";
556 alex-w 1995
            $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
1996
            $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ";
1997
            $query .= "JOIN ".$this->prefix."dtype dt ON d.disttype=dt.type_id ";
1998
            $query .= "WHERE r.rep_id='".$sRepID."'";
1999
            $rq =& $this->db->query($query);
594 alex-w 2000
            $rq->fetchInto($element);            
556 alex-w 2001
        }
2002
 
594 alex-w 2003
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";        
609 alex-w 2004
        $show .= "<div class='inputbox'><label for='rdist'>Дистрибутив:</label> ".$this->showVDList("rdist",$this->secure->checkInt($element["version_id"]),"innerhtml")."</div>\n";
626 alex-w 2005
        $show .= "<div class='inputbox'><label for='rname'>Название репозитория:</label> <input type='text' name='rname' value=\"".$this->secure->checkStr($element["repname"],1)."\"></div>\n";
2006
        $show .= "<div class='inputbox'><label for='rinfo'>Описание репозитория:</label> <input type='text' name='rinfo' value=\"".$this->secure->checkStr($element["repinfo"],1)."\"></div>\n";
2007
        $show .= "<div class='inputbox'><label for='rkey'>Ключ подписи репозитория:</label> <input type='text' name='rkey' value=\"".$this->secure->checkStr($element["repkey"],1)."\"></div>\n";
576 alex-w 2008
        $show .= "<div class='inputbox'><label for='rproto'>Протокол доступа:</label> ".$this->showProtoList("rproto",$this->secure->checkInt($element["proto_id"]),"innerhtml")."</div>\n";
588 alex-w 2009
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> ".$this->showHostsList("rhost",$this->secure->checkInt($element["rhost_id"]),"innerhtml")."</div>\n";
604 alex-w 2010
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> ".$this->showFoldersList("rfolder",$this->secure->checkInt($element["rfolder_id"]),"innerhtml")."</div>\n";
558 alex-w 2011
        $show .= "<div class='inputbox'><label for='rtype'>Тип репозитория:</label> ".$this->showRepType($this->secure->checkInt($element["rtype_id"]), "rtype")."</div>\n";
564 alex-w 2012
        $show .= "<div class='inputbox'><label for='rsects'>Секции репозитория:</label> <div class='formwrapper'>".$this->showSectionsList("rsects",$sRepID,"innerhtml")."</div></div>\n";
569 alex-w 2013
        $show .= "<div class='inputbox'><label for='rarchs'>Архитектуры:</label> <div class='formwrapper'>".$this->showArchList("rarchs",$sRepID,"innerhtml")."</div></div>\n";
613 alex-w 2014
        $show .= "<div class='inputbox'><label for='rscheme'>Схема репозитория:</label> ".$this->showSchemeList("rscheme",$this->secure->checkInt($element["scheme_id"]),"innerhtml")."</div>\n";
595 alex-w 2015
        $show .= "<div class='inputbox'><label for='rsign'>Подпись репозитория:</label> ".$this->showSignsList("rsign",$this->secure->checkInt($element["sign_id"]),"innerhtml")."</div>\n";
556 alex-w 2016
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
593 alex-w 2017
 
547 alex-w 2018
        return $show;
2019
    }
598 alex-w 2020
 
2021
    /**
2022
     * Добавление нового репозитория
2023
     *
2024
     * @author Alexander Wolf
2025
     * @category Core
2026
     *
2027
     * @param integer $verionID
2028
     * @param string $rname
2029
     * @param string $rinfo
2030
     * @param string $rkey
2031
     * @param integer $proto
2032
     * @param integer $rhost
2033
     * @param integer $rfolder
2034
     * @param integer $rtype
2035
     * @param array $sections
2036
     * @param array $arch
2037
     * @param integer $scheme
2038
     * @param integer $sign
2039
     * @return array
2040
     */
612 alex-w 2041
    public function addRepository($verionID, $rname, $rinfo, $rkey, $proto, $rhost, $rfolder, $rtype, $scheme, $sign, $sections, $arch) {
598 alex-w 2042
        $result = array();
2043
        $sVersionID     = $this->secure->checkInt($verionID);
2044
        $sRName         = $this->secure->checkStr($rname);
2045
        $sRInfo         = $this->secure->checkStr($rinfo);
2046
        $sRKey          = $this->secure->checkStr($rkey);
2047
        $sProto         = $this->secure->checkInt($proto);
2048
        $sRHost         = $this->secure->checkInt($rhost);
2049
        $sRFolder       = $this->secure->checkInt($rfolder);
2050
        $sRType         = $this->secure->checkInt($rtype);
2051
        $sRScheme       = $this->secure->checkInt($scheme);
2052
        $sRSign         = $this->secure->checkInt($sign);
2053
 
602 alex-w 2054
        $query = "INSERT INTO ".$this->prefix."repository SET proto_id='".$sProto."', rhost_id='".$sRHost."', rfolder_id='".$sRFolder."', version='".$sVersionID."', rtype_id='".$sRType."', scheme_id='".$sRScheme."', sign_id='".$sRSign."', repname='".$sRName."', repinfo='".$sRInfo."', repkey='".$sRKey."'";
598 alex-w 2055
        $rq =& $this->db->query($query);
2056
 
2057
        $query = "SELECT rep_id FROM ".$this->prefix."repository ORDER BY rep_id DESC LIMIT 0, 1";
2058
        $rq =& $this->db->query($query);
2059
        $rq->fetchInto($repository);
2060
 
2061
        for($i=0;$i<count($sections);$i++) {
2062
            $query = "INSERT INTO ".$this->prefix."sect2rep SET rep_id='".$repository["rep_id"]."', sect_id='".$sections[$i]."'";
2063
            $rq =& $this->db->query($query);
2064
        }
2065
 
2066
        for($i=0;$i<count($arch);$i++) {
2067
            $query = "INSERT INTO ".$this->prefix."arch2rep SET rep_id='".$repository["rep_id"]."', arch_id='".$arch[$i]."'";
2068
            $rq =& $this->db->query($query);
2069
        }
2070
 
2071
        if (PEAR::isError($this->db)) {
2072
            $result["ERR"] = 1;
2073
            $result["ERRINFO"] = $this->db->getMessage();
2074
        } else {
2075
            $result["ERR"] = 0;
2076
        }
2077
 
2078
        return $result;
2079
    }
618 alex-w 2080
 
2081
    /**
2082
     * Обновление информации о репозитории
2083
     *
2084
     * @author Alexander Wolf
2085
     * @category Core
2086
     *
2087
     * @param integer $repID
2088
     * @param integer $verionID
2089
     * @param string $rname
2090
     * @param string $rinfo
2091
     * @param string $rkey
2092
     * @param integer $proto
2093
     * @param integer $rhost
2094
     * @param integer $rfolder
2095
     * @param integer $rtype
2096
     * @param array $sections
2097
     * @param array $arch
2098
     * @param integer $scheme
2099
     * @param integer $sign
2100
     * @return array
2101
     */
2102
    public function updateRepository($repID, $verionID, $rname, $rinfo, $rkey, $proto, $rhost, $rfolder, $rtype, $scheme, $sign, $sections, $arch) {
2103
        $result = array();
2104
        $sRepID         = $this->secure->checkInt($repID);
2105
        $sVersionID     = $this->secure->checkInt($verionID);
2106
        $sRName         = $this->secure->checkStr($rname);
2107
        $sRInfo         = $this->secure->checkStr($rinfo);
2108
        $sRKey          = $this->secure->checkStr($rkey);
2109
        $sProto         = $this->secure->checkInt($proto);
2110
        $sRHost         = $this->secure->checkInt($rhost);
2111
        $sRFolder       = $this->secure->checkInt($rfolder);
2112
        $sRType         = $this->secure->checkInt($rtype);
2113
        $sRScheme       = $this->secure->checkInt($scheme);
2114
        $sRSign         = $this->secure->checkInt($sign);
2115
 
2116
        $query = "UPDATE ".$this->prefix."repository SET proto_id='".$sProto."', rhost_id='".$sRHost."', rfolder_id='".$sRFolder."', version='".$sVersionID."', rtype_id='".$sRType."', scheme_id='".$sRScheme."', sign_id='".$sRSign."', repname='".$sRName."', repinfo='".$sRInfo."', repkey='".$sRKey."' WHERE rep_id='".$sRepID."'";
2117
        $rq =& $this->db->query($query);
2118
 
2119
        $query = "DELETE FROM ".$this->prefix."sect2rep WHERE rep_id='".$sRepID."'";
2120
        $rq =& $this->db->query($query);
2121
        for($i=0;$i<count($sections);$i++) {
2122
            $query = "INSERT INTO ".$this->prefix."sect2rep SET rep_id='".$sRepID."', sect_id='".$sections[$i]."'";
2123
            $rq =& $this->db->query($query);
2124
        }
2125
 
2126
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE rep_id='".$sRepID."'";
2127
        $rq =& $this->db->query($query);
2128
        for($i=0;$i<count($arch);$i++) {
2129
            $query = "INSERT INTO ".$this->prefix."arch2rep SET rep_id='".$sRepID."', arch_id='".$arch[$i]."'";
2130
            $rq =& $this->db->query($query);
2131
        }
2132
 
2133
        if (PEAR::isError($this->db)) {
2134
            $result["ERR"] = 1;
2135
            $result["ERRINFO"] = $this->db->getMessage();
2136
        } else {
2137
            $result["ERR"] = 0;
2138
        }
2139
 
2140
        return $result;
2141
    }
2142
 
2143
    /**
2144
     * Удаление информации о репозитории
2145
     *
2146
     * @author Alexander Wolf
2147
     * @category Core
2148
     *
2149
     * @param integer $repID
2150
     * @return array
2151
     */
2152
    public function dropRepository($repID) {
2153
        $result = array();
2154
        $sRepID         = $this->secure->checkInt($repID);
2155
 
2156
        // Удаление репозитория
2157
        $query = "DELETE FROM ".$this->prefix."repository WHERE rep_id='".$sRepID."'";
2158
        $rq =& $this->db->query($query);
2159
        if (PEAR::isError($this->db)) {
2160
            $result["ERR"] = 1;
2161
            $result["ERRINFO"] = $this->db->getMessage();
2162
        } else {
2163
            $result["ERR"] = 0;
2164
        }
2165
 
2166
        // Удаление секций репозитория
2167
        $query = "DELETE FROM ".$this->prefix."sect2rep WHERE rep_id='".$sRepID."'";
2168
        $rq =& $this->db->query($query);
2169
        if (PEAR::isError($this->db)) {
2170
            $result["ERR"] = 1;
2171
            $result["ERRINFO"] = $this->db->getMessage();
2172
        } else {
2173
            $result["ERR"] = 0;
2174
        }
2175
 
2176
        // Удаление архитектур репозитория
2177
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE rep_id='".$sRepID."'";
2178
        $rq =& $this->db->query($query);
2179
        if (PEAR::isError($this->db)) {
2180
            $result["ERR"] = 1;
2181
            $result["ERRINFO"] = $this->db->getMessage();
2182
        } else {
2183
            $result["ERR"] = 0;
2184
        }
2185
 
2186
        return $result;
2187
    }
560 alex-w 2188
 
304 alex-w 2189
}
2190
 
356 alex-w 2191
?>