Хранилища Subversion ant

Редакция

Редакция 700 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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':
672 alex-w 310
                if ($rq->numRows()>0) {
311
                    $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
312
                    while ($rq->fetchInto($element)) {
700 alex-w 313
                        //TODO Сделать вывод информации об архитектурах репозитория
672 alex-w 314
                        $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";
315
                    }
316
                    $show .= "</fieldset>\n";
317 alex-w 317
                }
318
                break;
319
            case 'json':
320
                //TODO Доделать JSON-вывод списка репозиториев
321
                break;
322
        }
318 alex-w 323
 
324
        return $show;
317 alex-w 325
    }
326
 
463 alex-w 327
    /**
328
     * Добавление поддержки нового apt-дистрибутива
329
     *
330
     * @author Alexander Wolf
331
     * @category Core
332
     *
333
     * @param string $distname
334
     * @param integer $disttype
335
     * @param string $distua
336
     * @param byte $distlogo
337
     * @return array
338
     */
514 alex-w 339
    public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) {
321 alex-w 340
        $result = array();
582 alex-w 341
        $sDName = $this->secure->checkStr($distname);
321 alex-w 342
        $sDType = $this->secure->checkInt($disttype);
582 alex-w 343
        $sDUAgt = $this->secure->checkStr($distua);
514 alex-w 344
        $sDLogo = $this->secure->checkInt($distlogo);
321 alex-w 345
 
346
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
347
        $rq =& $this->db->query($query);
348
        if (PEAR::isError($this->db)) {
349
            $result["ERR"] = 1;
350
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 351
        } else {            
321 alex-w 352
            $result["ERR"] = 0;
353
        }
354
 
355
        return $result;
356
    }
357
 
463 alex-w 358
    /**
514 alex-w 359
     * Обновление информации о дистрибутиве
360
     *
361
     * @author Alexander Wolf
362
     * @category Core
363
     *
364
     * @param integer $distID
365
     * @param string $distname
366
     * @param integer $disttype
367
     * @param string $distua
368
     * @param integer $distlogo
369
     * @return array
370
     */
538 alex-w 371
    public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo = 0) {
514 alex-w 372
        $result = array();
373
        $sDID   = $this->secure->checkInt($distID);
579 alex-w 374
        $sDName = $this->secure->checkStr($distname);
514 alex-w 375
        $sDType = $this->secure->checkInt($disttype);
579 alex-w 376
        $sDUAgt = $this->secure->checkStr($distua);
514 alex-w 377
        $sDLogo = $this->secure->checkInt($distlogo);
378
 
538 alex-w 379
        if ($sDLogo!=0) {
380
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
381
        } else {
382
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."' WHERE dist_id='".$sDID."'";
383
        }
514 alex-w 384
        $rq =& $this->db->query($query);
385
        if (PEAR::isError($this->db)) {
386
            $result["ERR"] = 1;
387
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 388
        } else {            
514 alex-w 389
            $result["ERR"] = 0;
390
        }
391
 
392
        return $result;
393
    }
394
 
395
    /**
396
     * Удаление информации о дистрибутиве
397
     *
398
     * @author Alexander Wolf
399
     * @category Core
400
     *
401
     * @param integer $distID
402
     * @return array
403
     */
404
    public function dropDistribution($distID) {
405
        $result = array();
406
        $sDID   = $this->secure->checkInt($distID);
407
 
408
        // Удаление дистрибутива
409
        $query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
410
        $rq =& $this->db->query($query);
411
        if (PEAR::isError($this->db)) {
412
            $result["ERR"] = 1;
413
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 414
        } else {            
514 alex-w 415
            $result["ERR"] = 0;
416
        }
417
 
418
        // Удаление версий дистрибутива
419
        $query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
420
        $rq =& $this->db->query($query);
421
        if (PEAR::isError($this->db)) {
422
            $result["ERR"] = 1;
423
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 424
        } else {            
514 alex-w 425
            $result["ERR"] = 0;
426
        }
427
 
428
        return $result;
429
    }
430
 
431
    /**
463 alex-w 432
     * Добавление поддержки новой версии apt-дистрибутива
433
     *
434
     * @author Alexander Wolf
435
     * @category Core
436
     *
437
     * @param integer $distID
438
     * @param integer $version
439
     * @param string $vname
440
     * @param integer $vcodename
441
     * @return array
442
     */
368 alex-w 443
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
356 alex-w 444
        $result = array();
463 alex-w 445
        $sDistID    = $this->secure->checkInt($distID);
582 alex-w 446
        $sDVersion  = $this->secure->checkStr($version);
447
        $sDVName    = $this->secure->checkStr($vname);
448
        $sDVCName   = $this->secure->checkStr($vcodename);
356 alex-w 449
 
450
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
451
        $rq =& $this->db->query($query);
452
        if (PEAR::isError($this->db)) {
453
            $result["ERR"] = 1;
454
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 455
        } else {            
356 alex-w 456
            $result["ERR"] = 0;
457
        }
458
 
459
        return $result;
460
    }
358 alex-w 461
 
463 alex-w 462
    /**
514 alex-w 463
     * Редактирование информации о версии дистрибутива
464
     *
465
     * @author Alexander Wolf
466
     * @category Core
467
     *
468
     * @param integer $versionID
469
     * @param string $version
470
     * @param string $vname
471
     * @param string $vcodename
472
     * @return array
473
     */
474
    public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") {
475
        $result = array();
476
        $sVersID    = $this->secure->checkInt($versionID);
516 alex-w 477
        $sDVersion  = $this->secure->checkStr($version,1);
478
        $sDVName    = $this->secure->checkStr($vname,1);
479
        $sDVCName   = $this->secure->checkStr($vcodename,1);
514 alex-w 480
 
481
        $query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
482
        $rq =& $this->db->query($query);
483
        if (PEAR::isError($this->db)) {
484
            $result["ERR"] = 1;
485
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 486
        } else {            
514 alex-w 487
            $result["ERR"] = 0;
488
        }
489
 
490
        return $result;
491
    }
492
 
493
    /**
494
     * Удаление информации о версии дистрибутива
495
     *
496
     * @author Alexander Wolf
497
     * @category Core
498
     *
499
     * @param integer $versionID
500
     * @return array
501
     */
502
    public function dropDistVersion($versionID) {
503
        $result = array();
504
        $sVersID    = $this->secure->checkInt($versionID);
505
 
506
        // Удаление версии дистрибутива
507
        $query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
508
        $rq =& $this->db->query($query);
509
        if (PEAR::isError($this->db)) {
510
            $result["ERR"] = 1;
511
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 512
        } else {            
514 alex-w 513
            $result["ERR"] = 0;
514
        }
515
 
516
        // Удаление репозиториев этой версии дистрибутива
517
        $query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
518
        $rq =& $this->db->query($query);
519
        if (PEAR::isError($this->db)) {
520
            $result["ERR"] = 1;
521
            $result["ERRINFO"] = $this->db->getMessage();
517 alex-w 522
        } else {            
514 alex-w 523
            $result["ERR"] = 0;
524
        }
525
 
526
        return $result;
527
    }
528
 
529
    /**
463 alex-w 530
     * Отображение типа дистрибутива
531
     *
532
     * @author Alexander Wolf
533
     * @category Core
534
     *
535
     * @param string $name
536
     * @param byte $type
537
     * @return string
538
     */
368 alex-w 539
    public function showDistTypeForm($name = "dtype",$type = 0) {
329 alex-w 540
        $query = "SELECT * FROM ".$this->prefix."dtype";
541
        $rq =& $this->db->query($query);
542
        $show = "<select name='".$name."' id='".$name."'>\n";
543
        while ($rq->fetchInto($element)) {
347 alex-w 544
            if ($element["type_id"] == $type) {
545
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 546
            } else {
347 alex-w 547
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 548
            }
549
        }
550
        $show .= "</select>";
551
 
552
        return $show;
553
    }
554
 
463 alex-w 555
    /**
556
     * Отображение формы создания и редактирования apt-дистрибутива
557
     *
558
     * @author Alexander Wolf
559
     * @category Core
560
     *
561
     * @param integer $distID
562
     * @return string
563
     */
511 alex-w 564
    public function showDistributionForm($distID = 0, $info = '') {
329 alex-w 565
        $sDistID = $this->secure->checkInt($distID);
511 alex-w 566
        $sInfo = $this->secure->checkStr($info, 1);
567
        if ($sInfo == "") {
568
            $sInfo = "Дистрибутив";
569
        }
329 alex-w 570
        if ($sDistID != 0) {
571
            // Режим редактирования
572
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
573
            $rq =& $this->db->query($query);
574
            $rq->fetchInto($element);
575
        }
576
 
577
        if ($element["distlogo"] == 1) {
380 alex-w 578
            $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 579
        } else {
380 alex-w 580
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
329 alex-w 581
        }
582
 
511 alex-w 583
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
350 alex-w 584
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
585
        $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 586
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["disttype"])."</div>\n";
348 alex-w 587
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
329 alex-w 588
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
350 alex-w 589
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
329 alex-w 590
 
591
        return $show;
592
    }
593
 
628 alex-w 594
    /**
595
     * Генератор sources.list
596
     *
597
     * @author Alexander Wolf
598
     * @category Core
599
     * @version 1.0
600
     *
601
     * @param array $data
602
     * @return string
603
     */
668 alex-w 604
    public function showSourcesList($data) {      
646 alex-w 605
       // Извлекаем информацию о дистрибутиве и его версии
606
       $query  = "SELECT * FROM ".$this->prefix."distribution d ";
649 alex-w 607
       $query .= "JOIN ".$this->prefix."version v ON v.dist_id=d.dist_id ";
646 alex-w 608
       $query .= "JOIN ".$this->prefix."dtype t ON d.disttype=t.type_id ";
648 alex-w 609
       $query .= "WHERE d.dist_id='".$data["dist_id"]."' AND v.version_id='".$data["version_id"]."'";
646 alex-w 610
       $rq =& $this->db->query($query);
611
       $rq->fetchInto($dist);
663 alex-w 612
 
678 alex-w 613
       $show  = "# Список репозиториев для ".$this->secure->checkStr($dist["distname"],1)." ".$this->secure->checkStr($dist["version"],1)." ".$this->secure->checkStr($dist["vname"],1)."\n";
694 alex-w 614
       $show .= "# Этот sources.list сгенерирован при помощи ".$this->getEngineAttr('codename')." ".$this->getEngineAttr('version')."\n";
699 alex-w 615
       $show .= "# Адрес проекта: http://alex-w.org.ru/p/ant-ng/\n\n";
646 alex-w 616
 
617
       // Извлекаем информацию о репозиториях и строим sources.list
618
       if ($dist["type"]=="deb") {
619
           // Базовый репозиторий
620
           $query  = "SELECT * FROM ".$this->prefix."repository r ";
621
           $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
622
           $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
651 alex-w 623
           $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
646 alex-w 624
           $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
625
           $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
626
           $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";
650 alex-w 627
           $query .= "WHERE v.version_id='".$data["version_id"]."' AND r.rtype_id='1'";
646 alex-w 628
           $rq =& $this->db->query($query);
675 alex-w 629
           if ($rq->numRows()>0) {
630
                $rq->fetchInto($base);
631
                // Формируем type proto://host/folder
632
                $show .= "# ".$this->secure->checkStr($base["repinfo"],1)."\n";
633
                if ($base["repkey"]!="") {
634
                    $show .= "# Установка ключа: ".$this->secure->checkStr($base["repkey"],1)."\n";
635
                }
636
                $show .= $this->secure->checkStr($dist["type"],1)." ".$this->secure->checkStr($base["proto"],1).$this->secure->checkStr($base["rhost"],1).$this->secure->checkStr($base["rfolder"],1);
637
                $dvname = str_replace("{DIST}",$this->secure->checkStr($dist["vcodename"],1),$this->secure->checkStr($base["scheme"],1));
638
                // Формируем distname
639
                $show .= " ".$dvname." ";
640
                // Формируем sections
641
                $query  = "SELECT * FROM ".$this->prefix."section s ";
642
                $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
643
                $query .= "WHERE r.rep_id='".$base["rep_id"]."' AND (";
644
                for($i=0;$i<count($data["section"]);$i++) {
645
                    $query .= "s.sect_id='".$data["section"][$i]."' ";
646
                    if ($i<count($data["section"])-1) {
647
                        $query .= " OR ";
648
                    }
649
                }
650
                $query .= ")";
651
                $rq =& $this->db->query($query);
652
                while ($rq->fetchInto($sections)) {
653
                    $show .= $sections["secname"]." ";
654
                }
655
                $show .= "\n\n";
670 alex-w 656
           }
655 alex-w 657
 
676 alex-w 658
           if (count($data["repository"])>0) {
659
                // Репозитории обновлений и третьих лиц
660
                $query  = "SELECT * FROM ".$this->prefix."repository r ";
661
                $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
662
                $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
663
                $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
664
                $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
665
                $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
666
                $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";
667
                $query .= "WHERE r.rtype_id>'1' AND (";
668
                for($i=0;$i<count($data["repository"]);$i++) {
669
                    $query .= "r.rep_id='".$data["repository"][$i]."' ";
670
                        if ($i<count($data["repository"])-1) {
671
                            $query .= " OR ";
672
                        }
656 alex-w 673
                    }
676 alex-w 674
                $query .= ") ORDER BY r.rtype_id ASC";
675
                $req =& $this->db->query($query);
676
 
675 alex-w 677
                while ($req->fetchInto($updates)) {
678
                    // Формируем type proto://host/folder
679
                    $show .= "# ".$this->secure->checkStr($updates["repinfo"],1)."\n";
680
                    if ($updates["repkey"]!="") {
681
                        $show .= "# Установка ключа: ".$this->secure->checkStr($updates["repkey"],1)."\n";
682
                    }
683
                    $show .= $this->secure->checkStr($dist["type"],1)." ".$this->secure->checkStr($updates["proto"],1).$this->secure->checkStr($updates["rhost"],1).$this->secure->checkStr($updates["rfolder"],1);
684
                    $dvname = str_replace("{DIST}",$this->secure->checkStr($dist["vcodename"],1),$this->secure->checkStr($updates["scheme"],1));
685
                    // Формируем distname
686
                    $show .= " ".$dvname." ";
687
                    // Формируем sections
688
                    $query  = "SELECT * FROM ".$this->prefix."section s ";
689
                    $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
690
                    $query .= "WHERE r.rep_id='".$updates["rep_id"]."'";
691
                    $rq =& $this->db->query($query);
692
                    while ($rq->fetchInto($sections)) {
693
                        $show .= $sections["secname"]." ";
694
                    }
695
                    $show .= "\n\n";
670 alex-w 696
                }
675 alex-w 697
                $show .= "\n";
655 alex-w 698
           }
668 alex-w 699
       } else {
700
           // Базовый репозиторий
701
           $query  = "SELECT * FROM ".$this->prefix."repository r ";
702
           $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
703
           $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
704
           $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
705
           $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
706
           $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
707
           $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";          
708
           $query .= "WHERE v.version_id='".$data["version_id"]."' AND r.rtype_id='1'";
709
           $rq =& $this->db->query($query);
675 alex-w 710
           if ($rq->numRows()>0) {
711
                $rq->fetchInto($base);
712
                // Формируем type proto://host/folder
713
                $show .= "# ".$this->secure->checkStr($base["repinfo"],1)."\n";
714
                $show .= $this->secure->checkStr($dist["type"],1)." ";
715
                if ($base["sign_id"]!=0) {
716
                    $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$base["sign_id"]."'";
717
                    $rq =& $this->db->query($query);
718
                    $rq->fetchInto($sign);
719
                    $show .= "[".$this->secure->checkStr($sign["sname"],1)."] ";
720
                }
721
                $show .= $this->secure->checkStr($base["proto"],1).$this->secure->checkStr($base["rhost"],1).$this->secure->checkStr($base["rfolder"],1)." ";
722
                $show .= $this->secure->checkStr($base["scheme"],1)." ";
646 alex-w 723
 
675 alex-w 724
                // Формируем sections
725
                $query  = "SELECT * FROM ".$this->prefix."section s ";
726
                $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
727
                $query .= "WHERE r.rep_id='".$base["rep_id"]."' AND (";
728
                for($i=0;$i<count($data["section"]);$i++) {
729
                    $query .= "s.sect_id='".$data["section"][$i]."' ";
730
                    if ($i<count($data["section"])-1) {
731
                        $query .= " OR ";
732
                    }
733
                }
734
                $query .= ")";
735
                $rq =& $this->db->query($query);
736
                while ($rq->fetchInto($sections)) {
737
                    $show .= $sections["secname"]." ";
738
                }
739
                $show .= "\n\n";
668 alex-w 740
           }
741
 
677 alex-w 742
           if (count($data["repository"])>0) {
743
                // Репозитории обновлений и третьих лиц
744
                $query  = "SELECT * FROM ".$this->prefix."repository r ";
745
                $query .= "JOIN ".$this->prefix."protos p ON r.proto_id=p.proto_id ";
746
                $query .= "JOIN ".$this->prefix."rephost h ON r.rhost_id=h.rhost_id ";
747
                $query .= "JOIN ".$this->prefix."repfolder f ON r.rfolder_id=f.rfolder_id ";
748
                $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
749
                $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
750
                $query .= "JOIN ".$this->prefix."repscheme s ON r.scheme_id=s.scheme_id ";
751
                $query .= "WHERE r.rtype_id>'1' AND (";
752
                for($i=0;$i<count($data["repository"]);$i++) {
753
                    $query .= "r.rep_id='".$data["repository"][$i]."' ";
754
                        if ($i<count($data["repository"])-1) {
755
                            $query .= " OR ";
756
                        }
668 alex-w 757
                    }
677 alex-w 758
                $query .= ") ORDER BY r.rtype_id ASC";
759
                $req =& $this->db->query($query);
760
 
675 alex-w 761
                while ($req->fetchInto($updates)) {
762
                    // Формируем type proto://host/folder
763
                    $show .= "# ".$this->secure->checkStr($updates["repinfo"],1)."\n";
764
                    $show .= $this->secure->checkStr($dist["type"],1)." ";
765
                    if ($updates["sign_id"]!=0) {
705 alex-w 766
                        $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$updates["sign_id"]."'";
675 alex-w 767
                        $rqs =& $this->db->query($query);
768
                        $rqs->fetchInto($sign);
769
                        $show .= "[".$this->secure->checkStr($sign["sname"],1)."] ";
770
                    }
771
                    $show .= $this->secure->checkStr($updates["proto"],1).$this->secure->checkStr($updates["rhost"],1).$this->secure->checkStr($updates["rfolder"],1)." ";
772
                    $show .= $this->secure->checkStr($updates["scheme"],1)." ";
773
                    // Формируем sections
774
                    $query  = "SELECT * FROM ".$this->prefix."section s ";
775
                    $query .= "JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id ";
776
                    $query .= "WHERE r.rep_id='".$updates["rep_id"]."'";
777
                    $rq =& $this->db->query($query);
778
                    while ($rq->fetchInto($sections)) {
779
                        $show .= $sections["secname"]." ";
780
                    }
781
                    $show .= "\n\n";
668 alex-w 782
                }
675 alex-w 783
                $show .= "\n";
668 alex-w 784
           }
646 alex-w 785
       }
786
 
668 alex-w 787
       $HTTPHeader1 = "Content-length: ".strlen($show);
788
       $HTTPHeader2 = "Content-disposition: attachment; filename=sources.list\n\n";
789
 
790
       header($HTTPHeader1);
791
       header($HTTPHeader2);
628 alex-w 792
       return $show;
358 alex-w 793
    }
522 alex-w 794
 
463 alex-w 795
    /**
522 alex-w 796
     * Показывает список секций
797
     *
798
     * @author Alexander Wolf
799
     * @category Core
800
     *
801
     * @param string $name
802
     * @param string $actor
561 alex-w 803
     * @param string $format
522 alex-w 804
     * @return string
805
     */
560 alex-w 806
    public function showSectionsList($name, $actor, $format = 'html') {
807
        switch($format) {
808
            case 'html':
561 alex-w 809
                $query = "SELECT * FROM ".$this->prefix."section";
810
                $rq =& $this->db->query($query);
560 alex-w 811
                $show = "<ul>\n";
812
                while ($rq->fetchInto($element)) {
813
                    $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";
814
                }
815
                $show .= "</ul>";
816
                break;
817
            case 'innerhtml':
818
                $show = "";
561 alex-w 819
                $repID = $this->secure->checkInt($actor);
820
                if ($repID==0) {
821
                    $query = "SELECT * FROM ".$this->prefix."section";
822
                    $rq =& $this->db->query($query);
823
                    while ($rq->fetchInto($element)) {
567 alex-w 824
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 825
                    }
826
                } else {
827
                    $query = "SELECT * FROM ".$this->prefix."section s JOIN ".$this->prefix."sect2rep r ON s.sect_id=r.sect_id WHERE r.rep_id='$repID'";
828
                    $rq =& $this->db->query($query);
829
                    while ($rq->fetchInto($element)) {
567 alex-w 830
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."' checked>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 831
                    }
832
                    $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 833
                    $rq =& $this->db->query($query);
561 alex-w 834
                    while ($rq->fetchInto($element)) {
567 alex-w 835
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["sect_id"]."'>&nbsp;".$this->secure->checkStr($element["secname"],1)." ";
561 alex-w 836
                    }
837
                }
838
 
560 alex-w 839
                break;
522 alex-w 840
        }
841
 
842
        return $show;
843
    }
844
 
523 alex-w 845
    /**
846
     * Вывод формы редактирования/добавления секций
847
     *
848
     * @author Alexander Wolf
849
     * @category Core
850
     *
851
     * @param integer $sectionID
852
     * @param string $info
853
     * @return string
854
     */
855
    public function showSectionsForm($sectionID = 0, $info = "") {
522 alex-w 856
        $sSectID = $this->secure->checkInt($sectionID);
857
        $sInfo = $this->secure->checkStr($info, 1);
858
        if ($sInfo == "") {
859
            $sInfo = "Секция";
860
        }
861
        if ($sSectID != 0) {
862
            // Режим редактирования
863
            $query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
864
            $rq =& $this->db->query($query);
865
            $rq->fetchInto($element);
866
        }
867
 
868
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
869
        $show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
870
        $show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
871
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
872
 
873
        return $show;
874
    }
875
 
876
    /**
523 alex-w 877
     * Обновление информации о секции
878
     *
879
     * @author Alexander Wolf
880
     * @category Core
881
     *
882
     * @param integer $sectionID
883
     * @param string $sname
884
     * @param string $sinfo
885
     * @return array
886
     */
887
    public function updateSection($sectionID, $sname, $sinfo = "") {
888
        $result = array();
889
        $sSectID    = $this->secure->checkInt($sectionID);
579 alex-w 890
        $sSName     = $this->secure->checkStr($sname);
891
        $sSInfo     = $this->secure->checkStr($sinfo);
523 alex-w 892
 
893
        $query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
894
        $rq =& $this->db->query($query);
895
        if (PEAR::isError($this->db)) {
896
            $result["ERR"] = 1;
897
            $result["ERRINFO"] = $this->db->getMessage();
898
        } else {
899
            $result["ERR"] = 0;
900
        }
901
 
902
        return $result;
903
    }
904
 
905
    /**
906
     * Удаление информации о секции
907
     *
908
     * @author Alexander Wolf
909
     * @category Core
910
     *
911
     * @param integer $sectionID
912
     * @return array
913
     */
914
    public function dropSection($sectionID) {
915
        $result = array();
916
        $sSectID    = $this->secure->checkInt($sectionID);
917
 
918
        // Удаление секции
919
        $query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
920
        $rq =& $this->db->query($query);
921
        if (PEAR::isError($this->db)) {
922
            $result["ERR"] = 1;
923
            $result["ERRINFO"] = $this->db->getMessage();
924
        } else {
925
            $result["ERR"] = 0;
926
        }
927
 
928
        return $result;
929
    }
930
 
931
    /**
932
     * Добавление новой секции
933
     *
934
     * @author Alexander Wolf
935
     * @category Core
936
     *
937
     * @param string $sname
938
     * @param string $sinfo
939
     * @return array
940
     */
941
    public function addSection($sname, $sinfo = "") {
942
        $result = array();
582 alex-w 943
        $sSName = $this->secure->checkStr($sname);
944
        $sSInfo = $this->secure->checkStr($sinfo);
523 alex-w 945
 
946
        $query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
947
        $rq =& $this->db->query($query);
948
        if (PEAR::isError($this->db)) {
949
            $result["ERR"] = 1;
950
            $result["ERRINFO"] = $this->db->getMessage();
951
        } else {
952
            $result["ERR"] = 0;
953
        }
954
 
955
        return $result;
956
    }
957
 
958
    /**
568 alex-w 959
     * Вывод списка поддерживаемых архитектур
960
     *
961
     * @author Alexander Wolf
962
     * @category Core
963
     *
964
     * @param string $name
965
     * @param string $actor
966
     * @param string $format
967
     * @return string
968
     */
969
    public function showArchList($name, $actor, $format = 'list') {
970
        switch($format) {
971
            case 'list':
972
                $query = "SELECT * FROM ".$this->prefix."arch";
973
                $rq =& $this->db->query($query);
974
                $show = "<ul>\n";
975
                while ($rq->fetchInto($element)) {
976
                    $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";
977
                }
978
                $show .= "</ul>";
979
                break;
980
            case 'innerhtml':
981
                $show = "";
982
                $repID = $this->secure->checkInt($actor);
614 alex-w 983
                if ($repID==0) {
568 alex-w 984
                    $query = "SELECT * FROM ".$this->prefix."arch";
985
                    $rq =& $this->db->query($query);
986
                    while ($rq->fetchInto($element)) {
987
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
988
                    }
989
                } else {
990
                    $query = "SELECT * FROM ".$this->prefix."arch a JOIN ".$this->prefix."arch2rep r ON a.arch_id=r.arch_id WHERE r.rep_id='$repID'";
991
                    $rq =& $this->db->query($query);
992
                    while ($rq->fetchInto($element)) {
993
                        $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."' checked>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
994
                    }
995
                    $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')";
996
                    $rq =& $this->db->query($query);
610 alex-w 997
                    if ($rq->numRows()>0) {
998
                        while ($rq->fetchInto($element)) {
999
                            $show .= "<input type='checkbox' name='".$name."[]' value='".$element["arch_id"]."'>&nbsp;".$this->secure->checkStr($element["arch"],1)." ";
1000
                        }
568 alex-w 1001
                    }
1002
                }
1003
                break;
1004
        }
1005
        return $show;
1006
    }
1007
 
1008
    /**
1009
     * Добавление новой архитектуры
1010
     *
1011
     * @author Alexander Wolf
1012
     * @category Core
1013
     *
1014
     * @param string $arch
1015
     * @return array
1016
     */
1017
    public function addArch($arch) {
1018
        $result = array();
582 alex-w 1019
        $sArch = $this->secure->checkStr($arch);
568 alex-w 1020
 
1021
        $query = "INSERT INTO ".$this->prefix."arch SET arch='".$sArch."'";
1022
        $rq =& $this->db->query($query);
1023
        if (PEAR::isError($this->db)) {
1024
            $result["ERR"] = 1;
1025
            $result["ERRINFO"] = $this->db->getMessage();
1026
        } else {
1027
            $result["ERR"] = 0;
1028
        }
1029
 
1030
        return $result;
1031
    }
1032
 
1033
    /**
1034
     * Удаление информации об архитектуре
1035
     *
1036
     * @author Alexander Wolf
1037
     * @category Core
1038
     *
1039
     * @param integer $archID
1040
     * @return array
1041
     */
1042
    public function dropArch($archID) {
1043
        $result = array();
1044
        $sArchID    = $this->secure->checkInt($archID);
1045
 
1046
        // Удаление архитектуры
1047
        $query = "DELETE FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
1048
        $rq =& $this->db->query($query);
1049
        if (PEAR::isError($this->db)) {
1050
            $result["ERR"] = 1;
1051
            $result["ERRINFO"] = $this->db->getMessage();
1052
        } else {
1053
            $result["ERR"] = 0;
1054
        }
1055
 
1056
        // Удаление архитектуры из списка репозиториев
1057
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE arch_id='".$sArchID."'";
1058
        $rq =& $this->db->query($query);
1059
        if (PEAR::isError($this->db)) {
1060
            $result["ERR"] = 1;
1061
            $result["ERRINFO"] = $this->db->getMessage();
1062
        } else {
1063
            $result["ERR"] = 0;
1064
        }
1065
        return $result;
1066
    }
1067
 
1068
    /**
1069
     * Обновление информации об архитектуре
1070
     *
1071
     * @author Alexander Wolf
1072
     * @category Core
1073
     *
1074
     * @param integer $archID
1075
     * @param string $arch
1076
     * @return array
1077
     */
1078
    public function updateArch($archID, $arch) {
1079
        $result = array();
1080
        $sArchID    = $this->secure->checkInt($archID);
579 alex-w 1081
        $sArch      = $this->secure->checkStr($arch);
568 alex-w 1082
 
1083
        $query = "UPDATE ".$this->prefix."arch SET arch='".$sArch."' WHERE arch_id='".$sArchID."'";
1084
        $rq =& $this->db->query($query);
1085
        if (PEAR::isError($this->db)) {
1086
            $result["ERR"] = 1;
1087
            $result["ERRINFO"] = $this->db->getMessage();
1088
        } else {
1089
            $result["ERR"] = 0;
1090
        }
1091
 
1092
        return $result;
1093
    }
1094
 
1095
    /**
1096
     * Вывод формы редактирования/добавления архитектур
1097
     *
1098
     * @author Alexander Wolf
1099
     * @category Core
1100
     *
1101
     * @param integer $archID
1102
     * @param string $info
1103
     * @return string
1104
     */
1105
    public function showArchForm($archID = 0, $info = "") {
1106
        $sArchID = $this->secure->checkInt($archID);
1107
        $sInfo = $this->secure->checkStr($info, 1);
1108
        if ($sInfo == "") {
1109
            $sInfo = "Архитектура";
1110
        }
1111
        if ($sArchID != 0) {
1112
            // Режим редактирования
1113
            $query = "SELECT * FROM ".$this->prefix."arch WHERE arch_id='".$sArchID."'";
1114
            $rq =& $this->db->query($query);
1115
            $rq->fetchInto($element);
1116
        }
1117
 
1118
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1119
        $show .= "<div class='inputbox'><label for='arch'>Архитектура:</label> <input type='text' name='arch' id='arch' value='".$this->secure->checkStr($element["arch"],1)."'></div>\n";
1120
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1121
 
1122
        return $show;
1123
    }
1124
 
1125
    /**
570 alex-w 1126
     * Вывод списка схем репозиториев
1127
     *
1128
     * @author Alexander Wolf
1129
     * @category Core
1130
     *
1131
     * @param string $name
1132
     * @param string $actor
1133
     * @param string $format
1134
     * @return string
1135
     */
1136
    public function showSchemeList($name, $actor, $format = 'list') {
1137
        switch($format) {
1138
            case 'list':
1139
                $query = "SELECT * FROM ".$this->prefix."repscheme";
1140
                $rq =& $this->db->query($query);
1141
                $show = "<ul>\n";
1142
                while ($rq->fetchInto($element)) {
1143
                    $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";
1144
                }
1145
                $show .= "</ul>";
1146
                break;
1147
            case 'innerhtml':
611 alex-w 1148
                $schemeID = $this->secure->checkInt($actor);
570 alex-w 1149
                $query = "SELECT * FROM ".$this->prefix."repscheme";
1150
                $rq =& $this->db->query($query);
1151
                $show = "<select name='".$name."' id='".$name."'>\n";
1152
                while ($rq->fetchInto($element)) {
611 alex-w 1153
                    if ($element["scheme_id"]==$schemeID) {
570 alex-w 1154
                        $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."' selected>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
1155
                    } else {
611 alex-w 1156
                        $show .= "<option value='".$this->secure->checkInt($element["scheme_id"])."'>".$this->secure->checkStr($element["scheme"],1)."</option>\n";
570 alex-w 1157
                    }
1158
                }
1159
                $show .= "</select>";
1160
                break;
1161
        }
1162
        return $show;
1163
    }
1164
 
1165
    /**
1166
     * Добавление новой схемы репозитория
1167
     *
1168
     * @author Alexander Wolf
1169
     * @category Core
1170
     *
1171
     * @param string $scheme
1172
     * @return array
1173
     */
1174
    public function addScheme($scheme) {
1175
        $result = array();
582 alex-w 1176
        $sScheme = $this->secure->checkStr($scheme);
570 alex-w 1177
 
1178
        $query = "INSERT INTO ".$this->prefix."repscheme SET scheme='".$sScheme."'";
1179
        $rq =& $this->db->query($query);
1180
        if (PEAR::isError($this->db)) {
1181
            $result["ERR"] = 1;
1182
            $result["ERRINFO"] = $this->db->getMessage();
1183
        } else {
1184
            $result["ERR"] = 0;
1185
        }
1186
 
1187
        return $result;
1188
    }
1189
 
1190
    /**
1191
     * Удаление информации о схеме репозитория
1192
     *
1193
     * @author Alexander Wolf
1194
     * @category Core
1195
     *
1196
     * @param integer $schemeID
1197
     * @return array
1198
     */
1199
    public function dropScheme($schemeID) {
1200
        $result = array();
1201
        $sSchemeID    = $this->secure->checkInt($schemeID);
1202
 
1203
        // Удаление схемы
1204
        $query = "DELETE FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1205
        $rq =& $this->db->query($query);
1206
        if (PEAR::isError($this->db)) {
1207
            $result["ERR"] = 1;
1208
            $result["ERRINFO"] = $this->db->getMessage();
1209
        } else {
1210
            $result["ERR"] = 0;
1211
        }
1212
 
1213
        return $result;
1214
    }
1215
 
1216
    /**
1217
     * Обновление информации о схеме репозитория
1218
     *
1219
     * @author Alexander Wolf
1220
     * @category Core
1221
     *
1222
     * @param integer $schemeID
1223
     * @param string $info
1224
     * @return array
1225
     */
1226
    public function updateScheme($schemeID, $info) {
1227
        $result = array();
1228
        $sSchemeID    = $this->secure->checkInt($schemeID);
579 alex-w 1229
        $sScheme      = $this->secure->checkStr($info);
570 alex-w 1230
 
1231
        $query = "UPDATE ".$this->prefix."repscheme SET scheme='".$sScheme."' WHERE scheme_id='".$sSchemeID."'";
1232
        $rq =& $this->db->query($query);
1233
        if (PEAR::isError($this->db)) {
1234
            $result["ERR"] = 1;
1235
            $result["ERRINFO"] = $this->db->getMessage();
1236
        } else {
1237
            $result["ERR"] = 0;
1238
        }
1239
 
1240
        return $result;
1241
    }
1242
 
1243
    /**
1244
     * Вывод формы редактирования/добавления схем репозиториев
1245
     *
1246
     * @author Alexander Wolf
1247
     * @category Core
1248
     *
1249
     * @param integer $schemeID
1250
     * @param string $info
1251
     * @return string
1252
     */
1253
    public function showSchemeForm($schemeID = 0, $info = "") {
1254
        $sSchemeID = $this->secure->checkInt($schemeID);
1255
        $sInfo = $this->secure->checkStr($info, 1);
1256
        if ($sInfo == "") {
1257
            $sInfo = "Схема репозитория";
1258
        }
571 alex-w 1259
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
570 alex-w 1260
        if ($sSchemeID != 0) {
1261
            // Режим редактирования
1262
            $query = "SELECT * FROM ".$this->prefix."repscheme WHERE scheme_id='".$sSchemeID."'";
1263
            $rq =& $this->db->query($query);
573 alex-w 1264
            $rq->fetchInto($element);            
1265
        }
571 alex-w 1266
 
573 alex-w 1267
        $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 1268
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1269
 
1270
        return $show;
1271
    }
1272
 
1273
    /**
574 alex-w 1274
     * Вывод списка протоколов
1275
     *
1276
     * @author Alexander Wolf
1277
     * @category Core
1278
     *
1279
     * @param string $name
1280
     * @param string $actor
1281
     * @param string $format
1282
     * @return string
1283
     */
1284
    public function showProtoList($name, $actor, $format = 'list') {
1285
        switch($format) {
1286
            case 'list':
1287
                $query = "SELECT * FROM ".$this->prefix."protos";
1288
                $rq =& $this->db->query($query);
1289
                $show = "<ul>\n";
1290
                while ($rq->fetchInto($element)) {
1291
                    $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";
1292
                }
1293
                $show .= "</ul>";
1294
                break;
1295
            case 'innerhtml':
1296
                $protoID = $this->secure->checkInt($actor);
1297
                $query = "SELECT * FROM ".$this->prefix."protos";
1298
                $rq =& $this->db->query($query);
1299
                $show = "<select name='".$name."' id='".$name."'>\n";
1300
                while ($rq->fetchInto($element)) {
1301
                    if ($element["proto_id"]==$protoID) {
1302
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."' selected>".$this->secure->checkStr($element["proto"],1)."</option>\n";
1303
                    } else {
580 alex-w 1304
                        $show .= "<option value='".$this->secure->checkInt($element["proto_id"])."'>".$this->secure->checkStr($element["proto"],1)."</option>\n";
574 alex-w 1305
                    }
1306
                }
1307
                $show .= "</select>";
1308
                break;
1309
        }
1310
        return $show;
1311
    }
1312
 
1313
    /**
1314
     * Добавление нового протокола
1315
     *
1316
     * @author Alexander Wolf
1317
     * @category Core
1318
     *
1319
     * @param string $proto
1320
     * @return array
1321
     */
1322
    public function addProto($proto) {
1323
        $result = array();
582 alex-w 1324
        $sProto = $this->secure->checkStr($proto);
574 alex-w 1325
 
1326
        $query = "INSERT INTO ".$this->prefix."protos SET proto='".$sProto."'";
1327
        $rq =& $this->db->query($query);
1328
        if (PEAR::isError($this->db)) {
1329
            $result["ERR"] = 1;
1330
            $result["ERRINFO"] = $this->db->getMessage();
1331
        } else {
1332
            $result["ERR"] = 0;
1333
        }
1334
 
1335
        return $result;
1336
    }
1337
 
1338
    /**
1339
     * Удаление информации о протоколе
1340
     *
1341
     * @author Alexander Wolf
1342
     * @category Core
1343
     *
1344
     * @param integer $protoID
1345
     * @return array
1346
     */
1347
    public function dropProto($protoID) {
1348
        $result = array();
1349
        $sProtoID    = $this->secure->checkInt($protoID);
1350
 
1351
        // Удаление протокола
1352
        $query = "DELETE FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1353
        $rq =& $this->db->query($query);
1354
        if (PEAR::isError($this->db)) {
1355
            $result["ERR"] = 1;
1356
            $result["ERRINFO"] = $this->db->getMessage();
1357
        } else {
1358
            $result["ERR"] = 0;
1359
        }
1360
 
1361
        return $result;
1362
    }
1363
 
1364
    /**
1365
     * Обновление информации о протоколе
1366
     *
1367
     * @author Alexander Wolf
1368
     * @category Core
1369
     *
1370
     * @param integer $protoID
1371
     * @param string $info
1372
     * @return array
1373
     */
1374
    public function updateProto($protoID, $info) {
1375
        $result = array();
1376
        $sProtoID    = $this->secure->checkInt($protoID);
579 alex-w 1377
        $sProto      = $this->secure->checkStr($info);
574 alex-w 1378
 
1379
        $query = "UPDATE ".$this->prefix."protos SET proto='".$sProto."' WHERE proto_id='".$sProtoID."'";
1380
        $rq =& $this->db->query($query);
1381
        if (PEAR::isError($this->db)) {
1382
            $result["ERR"] = 1;
1383
            $result["ERRINFO"] = $this->db->getMessage();
1384
        } else {
1385
            $result["ERR"] = 0;
1386
        }
1387
 
1388
        return $result;
1389
    }
1390
 
1391
    /**
1392
     * Вывод формы редактирования/добавления протоколов
1393
     *
1394
     * @author Alexander Wolf
1395
     * @category Core
1396
     *
1397
     * @param integer $protoID
1398
     * @param string $info
1399
     * @return string
1400
     */
1401
    public function showProtoForm($protoID = 0, $info = "") {
1402
        $sProtoID = $this->secure->checkInt($protoID);
1403
        $sInfo = $this->secure->checkStr($info, 1);
1404
        if ($sInfo == "") {
1405
            $sInfo = "Протокол доступа";
1406
        }
1407
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1408
        if ($sProtoID != 0) {
1409
            // Режим редактирования
1410
            $query = "SELECT * FROM ".$this->prefix."protos WHERE proto_id='".$sProtoID."'";
1411
            $rq =& $this->db->query($query);
1412
            $rq->fetchInto($element);
1413
        }
1414
 
1415
        $show .= "<div class='inputbox'><label for='proto'>Протокол доступа:</label> <input type='text' name='proto' id='proto' value='".$this->secure->checkStr($element["proto"],1)."'></div>\n";
1416
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1417
 
1418
        return $show;
1419
    }
1420
 
1421
    /**
582 alex-w 1422
     * Вывод списка хостов
1423
     *
1424
     * @author Alexander Wolf
1425
     * @category Core
1426
     *
1427
     * @param string $name
1428
     * @param string $actor
1429
     * @param string $format
1430
     * @return string
1431
     */
1432
    public function showHostsList($name, $actor, $format = 'list') {
1433
        switch($format) {
1434
            case 'list':
1435
                $query = "SELECT * FROM ".$this->prefix."rephost";
1436
                $rq =& $this->db->query($query);
1437
                $show = "<ul>\n";
1438
                while ($rq->fetchInto($element)) {
1439
                    $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";
1440
                }
1441
                $show .= "</ul>";
1442
                break;
1443
            case 'innerhtml':
1444
                $hostID = $this->secure->checkInt($actor);
1445
                $query = "SELECT * FROM ".$this->prefix."rephost";
1446
                $rq =& $this->db->query($query);
1447
                $show = "<select name='".$name."' id='".$name."'>\n";
1448
                while ($rq->fetchInto($element)) {
1449
                    if ($element["rhost_id"]==$hostID) {
1450
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."' selected>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1451
                    } else {
1452
                        $show .= "<option value='".$this->secure->checkInt($element["rhost_id"])."'>".$this->secure->checkStr($element["rhost"],1)."</option>\n";
1453
                    }
1454
                }
1455
                $show .= "</select>";
1456
                break;
1457
        }
1458
        return $show;
1459
    }
1460
 
1461
    /**
1462
     * Добавление нового хоста
1463
     *
1464
     * @author Alexander Wolf
1465
     * @category Core
1466
     *
1467
     * @param string $host
1468
     * @return array
1469
     */
1470
    public function addHost($host) {
1471
        $result = array();
1472
        $sHost = $this->secure->checkStr($host);
1473
 
586 alex-w 1474
        $query = "INSERT INTO ".$this->prefix."rephost SET rhost='".$sHost."'";
582 alex-w 1475
        $rq =& $this->db->query($query);
1476
        if (PEAR::isError($this->db)) {
1477
            $result["ERR"] = 1;
1478
            $result["ERRINFO"] = $this->db->getMessage();
1479
        } else {
1480
            $result["ERR"] = 0;
1481
        }
1482
 
1483
        return $result;
1484
    }
1485
 
1486
    /**
1487
     * Удаление информации о хосте
1488
     *
1489
     * @author Alexander Wolf
1490
     * @category Core
1491
     *
1492
     * @param integer $hostID
1493
     * @return array
1494
     */
1495
    public function dropHost($hostID) {
1496
        $result = array();
1497
        $sHostID    = $this->secure->checkInt($hostID);
1498
 
1499
        // Удаление хоста
1500
        $query = "DELETE FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1501
        $rq =& $this->db->query($query);
1502
        if (PEAR::isError($this->db)) {
1503
            $result["ERR"] = 1;
1504
            $result["ERRINFO"] = $this->db->getMessage();
1505
        } else {
1506
            $result["ERR"] = 0;
1507
        }
1508
 
1509
        return $result;
1510
    }
1511
 
1512
    /**
1513
     * Обновление информации о хосте
1514
     *
1515
     * @author Alexander Wolf
1516
     * @category Core
1517
     *
1518
     * @param integer $hostID
1519
     * @param string $info
1520
     * @return array
1521
     */
1522
    public function updateHost($hostID, $info) {
1523
        $result = array();
1524
        $sHostID    = $this->secure->checkInt($hostID);
1525
        $sHost      = $this->secure->checkStr($info);
1526
 
1527
        $query = "UPDATE ".$this->prefix."rephost SET rhost='".$sHost."' WHERE rhost_id='".$sHostID."'";
1528
        $rq =& $this->db->query($query);
1529
        if (PEAR::isError($this->db)) {
1530
            $result["ERR"] = 1;
1531
            $result["ERRINFO"] = $this->db->getMessage();
1532
        } else {
1533
            $result["ERR"] = 0;
1534
        }
1535
 
1536
        return $result;
1537
    }
1538
 
1539
    /**
1540
     * Вывод формы редактирования/добавления хостов
1541
     *
1542
     * @author Alexander Wolf
1543
     * @category Core
1544
     *
1545
     * @param integer $hostID
1546
     * @param string $info
1547
     * @return string
1548
     */
1549
    public function showHostForm($hostID = 0, $info = "") {
1550
        $sHostID = $this->secure->checkInt($hostID);
1551
        $sInfo = $this->secure->checkStr($info, 1);
1552
        if ($sInfo == "") {
1553
            $sInfo = "Хост репозитория";
1554
        }
1555
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1556
        if ($sHostID != 0) {
1557
            // Режим редактирования
1558
            $query = "SELECT * FROM ".$this->prefix."rephost WHERE rhost_id='".$sHostID."'";
1559
            $rq =& $this->db->query($query);
1560
            $rq->fetchInto($element);
1561
        }
1562
 
1563
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> <input type='text' name='rhost' id='rhost' value='".$this->secure->checkStr($element["rhost"],1)."'></div>\n";
1564
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1565
 
1566
        return $show;
1567
    }
1568
 
1569
    /**
589 alex-w 1570
     * Вывод списка корневых папок
1571
     *
1572
     * @author Alexander Wolf
1573
     * @category Core
1574
     *
1575
     * @param string $name
1576
     * @param string $actor
1577
     * @param string $format
1578
     * @return string
1579
     */
1580
    public function showFoldersList($name, $actor, $format = 'list') {
1581
        switch($format) {
1582
            case 'list':
1583
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1584
                $rq =& $this->db->query($query);
1585
                $show = "<ul>\n";
1586
                while ($rq->fetchInto($element)) {
1587
                    $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";
1588
                }
1589
                $show .= "</ul>";
1590
                break;
1591
            case 'innerhtml':
1592
                $folderID = $this->secure->checkInt($actor);
1593
                $query = "SELECT * FROM ".$this->prefix."repfolder";
1594
                $rq =& $this->db->query($query);
1595
                $show = "<select name='".$name."' id='".$name."'>\n";
1596
                while ($rq->fetchInto($element)) {
1597
                    if ($element["rfolder_id"]==$folderID) {
1598
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."' selected>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1599
                    } else {
1600
                        $show .= "<option value='".$this->secure->checkInt($element["rfolder_id"])."'>".$this->secure->checkStr($element["rfolder"],1)."</option>\n";
1601
                    }
1602
                }
1603
                $show .= "</select>";
1604
                break;
1605
        }
1606
        return $show;
1607
    }
1608
 
1609
    /**
1610
     * Добавление нового корневого каталога
1611
     *
1612
     * @author Alexander Wolf
1613
     * @category Core
1614
     *
1615
     * @param string $flder
1616
     * @return array
1617
     */
1618
    public function addFolder($folder) {
1619
        $result = array();
1620
        $sFolder = $this->secure->checkStr($folder);
1621
 
1622
        $query = "INSERT INTO ".$this->prefix."repfolder SET rfolder='".$sFolder."'";
1623
        $rq =& $this->db->query($query);
1624
        if (PEAR::isError($this->db)) {
1625
            $result["ERR"] = 1;
1626
            $result["ERRINFO"] = $this->db->getMessage();
1627
        } else {
1628
            $result["ERR"] = 0;
1629
        }
1630
 
1631
        return $result;
1632
    }
1633
 
1634
    /**
1635
     * Удаление информации о корневой папке
1636
     *
1637
     * @author Alexander Wolf
1638
     * @category Core
1639
     *
1640
     * @param integer $folderID
1641
     * @return array
1642
     */
1643
    public function dropFolder($folderID) {
1644
        $result = array();
1645
        $sFolderID    = $this->secure->checkInt($folderID);
1646
 
1647
        // Удаление корневой папки
1648
        $query = "DELETE FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1649
        $rq =& $this->db->query($query);
1650
        if (PEAR::isError($this->db)) {
1651
            $result["ERR"] = 1;
1652
            $result["ERRINFO"] = $this->db->getMessage();
1653
        } else {
1654
            $result["ERR"] = 0;
1655
        }
1656
 
1657
        return $result;
1658
    }
1659
 
1660
    /**
1661
     * Обновление информации о корневой папки
1662
     *
1663
     * @author Alexander Wolf
1664
     * @category Core
1665
     *
1666
     * @param integer $folderID
1667
     * @param string $info
1668
     * @return array
1669
     */
1670
    public function updateFolder($folderID, $info) {
1671
        $result = array();
1672
        $sFolderID    = $this->secure->checkInt($folderID);
1673
        $sFolder      = $this->secure->checkStr($info);
1674
 
1675
        $query = "UPDATE ".$this->prefix."repfolder SET rfolder='".$sFolder."' WHERE rfolder_id='".$sFolderID."'";
1676
        $rq =& $this->db->query($query);
1677
        if (PEAR::isError($this->db)) {
1678
            $result["ERR"] = 1;
1679
            $result["ERRINFO"] = $this->db->getMessage();
1680
        } else {
1681
            $result["ERR"] = 0;
1682
        }
1683
 
1684
        return $result;
1685
    }
1686
 
1687
    /**
1688
     * Вывод формы редактирования/добавления корневых папок
1689
     *
1690
     * @author Alexander Wolf
1691
     * @category Core
1692
     *
1693
     * @param integer $folderID
1694
     * @param string $info
1695
     * @return string
1696
     */
1697
    public function showFolderForm($folderID = 0, $info = "") {
1698
        $sFolderID = $this->secure->checkInt($folderID);
1699
        $sInfo = $this->secure->checkStr($info, 1);
1700
        if ($sInfo == "") {
1701
            $sInfo = "Корневая папка";
1702
        }
1703
        if ($sFolderID != 0) {
1704
            // Режим редактирования
1705
            $query = "SELECT * FROM ".$this->prefix."repfolder WHERE rfolder_id='".$sFolderID."'";
1706
            $rq =& $this->db->query($query);
1707
            $rq->fetchInto($element);
1708
        }
1709
 
1710
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1711
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> <input type='text' name='rfolder' id='rfolder' value='".$this->secure->checkStr($element["rfolder"],1)."'></div>\n";
1712
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1713
 
1714
        return $show;
1715
    }
1716
 
1717
    /**
539 alex-w 1718
     * Показывает список подписей
1719
     *
1720
     * @author Alexander Wolf
1721
     * @category Core
1722
     *
1723
     * @param string $name
1724
     * @param string $actor
596 alex-w 1725
     * @param string $format
539 alex-w 1726
     * @return string
1727
     */
594 alex-w 1728
    public function showSignsList($name, $actor, $format = 'list') {
539 alex-w 1729
        $query = "SELECT * FROM ".$this->prefix."signs";
1730
        $rq =& $this->db->query($query);
594 alex-w 1731
        switch ($format) {
1732
            case 'list':
1733
                $show = "<ul>\n";
1734
                while ($rq->fetchInto($element)) {
1735
                    $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";
1736
                }
1737
                $show .= "</ul>";
1738
                break;
1739
            case 'innerhtml':
1740
                $signID = $this->secure->checkInt($actor);
1741
                $show  = "<select name='".$name."' id='".$name."'>\n";
1742
                $show .= "<option value='0'>Подписи нет</option>\n";
1743
                while ($rq->fetchInto($element)) {
1744
                    if ($element["sign_id"]==$signID) {
1745
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."' selected>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1746
                    } else {
1747
                        $show .= "<option value='".$this->secure->checkInt($element["sign_id"])."'>".$this->secure->checkStr($element["sname"],1)."</option>\n";
1748
                    }
1749
                }
1750
                $show .= "</select>\n";
1751
                break;
539 alex-w 1752
        }
1753
 
1754
        return $show;
1755
    }
1756
 
1757
    /**
1758
     * Вывод формы редактирования/добавления подписей
1759
     *
1760
     * @author Alexander Wolf
1761
     * @category Core
1762
     *
1763
     * @param integer $sectionID
1764
     * @param string $info
1765
     * @return string
1766
     */
1767
    public function showSignsForm($signID = 0, $info = "") {
1768
        $sSignID = $this->secure->checkInt($signID);
1769
        $sInfo = $this->secure->checkStr($info, 1);
1770
        if ($sInfo == "") {
1771
            $sInfo = "Подписи";
1772
        }
1773
        if ($sSignID != 0) {
1774
            // Режим редактирования
1775
            $query = "SELECT * FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1776
            $rq =& $this->db->query($query);
1777
            $rq->fetchInto($element);
1778
        }
1779
 
1780
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
1781
        $show .= "<div class='inputbox'><label for='sname'>Название подписи:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["sname"],1)."'></div>\n";
1782
        $show .= "<div class='inputbox'><label for='sinfo'>Описание подписи:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sinfo"],1)."'></div>\n";
1783
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
1784
 
1785
        return $show;
1786
    }
1787
 
1788
    /**
1789
     * Обновление информации о секции
1790
     *
1791
     * @author Alexander Wolf
1792
     * @category Core
1793
     *
1794
     * @param integer $sectionID
1795
     * @param string $sname
1796
     * @param string $sinfo
1797
     * @return array
1798
     */
1799
    public function updateSign($signID, $sname, $sinfo = "") {
1800
        $result = array();
1801
        $sSignID    = $this->secure->checkInt($signID);
579 alex-w 1802
        $sSName     = $this->secure->checkStr($sname);
1803
        $sSInfo     = $this->secure->checkStr($sinfo);
539 alex-w 1804
 
1805
        $query = "UPDATE ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."' WHERE sign_id='".$sSignID."'";
1806
        $rq =& $this->db->query($query);
1807
        if (PEAR::isError($this->db)) {
1808
            $result["ERR"] = 1;
1809
            $result["ERRINFO"] = $this->db->getMessage();
1810
        } else {
1811
            $result["ERR"] = 0;
1812
        }
1813
 
1814
        return $result;
1815
    }
1816
 
1817
    /**
1818
     * Удаление информации о подписи
1819
     *
1820
     * @author Alexander Wolf
1821
     * @category Core
1822
     *
1823
     * @param integer $sectionID
1824
     * @return array
1825
     */
540 alex-w 1826
    public function dropSign($signID) {
539 alex-w 1827
        $result = array();
1828
        $sSignID    = $this->secure->checkInt($signID);
1829
 
1830
        // Удаление подписи
1831
        $query = "DELETE FROM ".$this->prefix."signs WHERE sign_id='".$sSignID."'";
1832
        $rq =& $this->db->query($query);
1833
        if (PEAR::isError($this->db)) {
1834
            $result["ERR"] = 1;
1835
            $result["ERRINFO"] = $this->db->getMessage();
1836
        } else {
1837
            $result["ERR"] = 0;
1838
        }
1839
 
1840
        return $result;
1841
    }
1842
 
1843
    /**
540 alex-w 1844
     * Добавление новой подписи
539 alex-w 1845
     *
1846
     * @author Alexander Wolf
1847
     * @category Core
1848
     *
1849
     * @param string $sname
1850
     * @param string $sinfo
1851
     * @return array
1852
     */
540 alex-w 1853
    public function addSign($sname, $sinfo = "") {
539 alex-w 1854
        $result = array();
582 alex-w 1855
        $sSName = $this->secure->checkStr($sname);
1856
        $sSInfo = $this->secure->checkStr($sinfo);
539 alex-w 1857
 
540 alex-w 1858
        $query = "INSERT INTO ".$this->prefix."signs SET sname='".$sSName."', sinfo='".$sSInfo."'";
539 alex-w 1859
        $rq =& $this->db->query($query);
1860
        if (PEAR::isError($this->db)) {
1861
            $result["ERR"] = 1;
1862
            $result["ERRINFO"] = $this->db->getMessage();
1863
        } else {
1864
            $result["ERR"] = 0;
1865
        }
1866
 
1867
        return $result;
1868
    }
540 alex-w 1869
 
539 alex-w 1870
    /**
463 alex-w 1871
     * Проверка пароля (из формы авторизации)
1872
     *
1873
     * @author Alexander Wolf
1874
     * @category Core
1875
     *
1876
     * @param string $word
1877
     * @return array
1878
     */
368 alex-w 1879
    public function checkSign($word) {
359 alex-w 1880
        $result = array();
1881
 
1882
        $sHash = $this->secure->encryptStr($word);
1883
        $pwd   = $this->getOption("passwd");
1884
        if ($sHash == $pwd["OptValue"]) {
1885
            $result["ERR"] = 0;
1886
            $result["Location"] = "manager.php";
1887
            setcookie($this->cookie, $sHash);
1888
        } else {
1889
            $result["ERR"] = 1;
1890
            $result["ERRINFO"] = "Password not valid";
368 alex-w 1891
            $result["Location"] = "manager.php?error=1";
359 alex-w 1892
        }
1893
 
1894
        return $result;
358 alex-w 1895
    }
357 alex-w 1896
 
463 alex-w 1897
    /**
1898
     * Проверка пароля (из cookies)
1899
     *
1900
     * @author Alexander Wolf
1901
     * @category Core
1902
     *
1903
     * @param string $hash
1904
     * @return array
1905
     */
368 alex-w 1906
    public function checkCookieSign($hash) {
359 alex-w 1907
        $result = array();
1908
 
1909
        $pwd = $this->getOption("passwd");
1910
        if ($hash == $pwd["OptValue"]) {
1911
            $result["ERR"] = 0;
1912
        } else {
1913
            $result["ERR"] = 1;
1914
            $result["ERRINFO"] = "Hash not valid";
368 alex-w 1915
            $result["Location"] = "manager.php";
359 alex-w 1916
        }
1917
 
1918
        return $result;
1919
    }
1920
 
463 alex-w 1921
    /**
1922
     * Форма ввода пароля
1923
     *
1924
     * @author Alexander Wolf
1925
     * @category Core
1926
     *
1927
     * @return string
1928
     */
368 alex-w 1929
    public function showSigninForm() {
425 alex-w 1930
        $show  = "<div id='regform'>";
1931
        $show .= "<form action='process.php' method='post'>\n";
368 alex-w 1932
        $show .= "<fieldset><legend>Пароль</legend>\n";
1933
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
427 alex-w 1934
        $show .= "<input type='password' name='word' value=''>\n";
368 alex-w 1935
        $show .= "<input type='submit' value=' Войти '>\n";
425 alex-w 1936
        $show .= "</fieldset>\n</form></div>\n";
368 alex-w 1937
 
1938
        return $show;
1939
    }
1940
 
463 alex-w 1941
    /**
1942
     * Обновление пароля
1943
     *
1944
     * @author Alexander Wolf
1945
     * @category Core
1946
     *
1947
     * @param string $word1
1948
     * @param string $word2
1949
     * @return array
1950
     */
368 alex-w 1951
    public function updatePassword($word1, $word2) {
359 alex-w 1952
        $result = array();
1953
 
1954
        if ($word1 == $word2) {
1955
            $sWord = $this->secure->encryptStr($word1);
1956
            $r = $this->setOption("passwd", $sWord);
1957
            $result = $r;
1958
        } else {
1959
            $result["ERR"] = 1;
1960
            $result["ERRINFO"] = "Passwords is mismatch";
1961
        }
1962
 
1963
        return $result;
1964
    }
1965
 
504 alex-w 1966
    /**
509 alex-w 1967
     * Отображение формы создания и редактирования версии apt-дистрибутива
504 alex-w 1968
     *
1969
     * @author Alexander Wolf
1970
     * @category Core
1971
     *
1972
     * @param string $name
1973
     * @param string $actor
1974
     * @param integer $versionID
1975
     * @return string
1976
     */
511 alex-w 1977
    public function showDistVersionsForm($versionID = 0, $info = '') {
509 alex-w 1978
        $sVersionID = $this->secure->checkInt($versionID);
511 alex-w 1979
        $sInfo = $this->secure->checkStr($info, 1);
1980
        if ($sInfo == "") {
1981
            $sInfo = "Версия дистрибутива";
1982
        }
509 alex-w 1983
        if ($sVersionID != 0) {
1984
            // Режим редактирования
556 alex-w 1985
            $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 1986
            $rq =& $this->db->query($query);
1987
            $rq->fetchInto($element);
509 alex-w 1988
        }
1989
 
511 alex-w 1990
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
510 alex-w 1991
        if ($sVersionID != 0) {
1992
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
1993
        } else {
1994
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
1995
        }
509 alex-w 1996
        $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
1997
        $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
1998
        $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
1999
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
495 alex-w 2000
 
504 alex-w 2001
        return $show;
509 alex-w 2002
    }    
504 alex-w 2003
 
520 alex-w 2004
    /**
2005
     * Парсер схемы адреса репозитория
2006
     * FIXME Возможно не потребуется
2007
     *
2008
     * @author Alexander Wolf
2009
     * @category Core
2010
     *
2011
     * @param string $repstring
2012
     * @return integer
2013
     */
2014
    public function repositoryParser($repstring) {
2015
        $tokens = array();
2016
        $sections = array();
2017
        $tokens = split(" ",$repstring);
2018
 
2019
        if ($tokens[0] == "deb") {
2020
            // debian/ubuntu репозиторий "type proto://host/folder distr sections"
2021
            $url = parse_url($tokens[1]);
2022
            $distr  = $tokens[2];
2023
 
2024
            for($i=3;$i<count($tokens);$i++) {
2025
                $sections[] = $tokens[$i];
2026
            }
2027
        } else {
2028
            // altlinux репозиторий "type [sign] proto://host/folder base repname"
2029
            if (stripos($tokens[1],"]")!=0) {
2030
                $sign = $tokens[1];
2031
                $url = parse_url($tokens[2]);
2032
                $base = $tokens[3];
2033
                $repname = $tokens[4];
2034
            } else {
2035
                $url = parse_url($tokens[1]);
2036
                $base = $tokens[2];
2037
                $repname = $tokens[3];
2038
            }
2039
        }
2040
 
2041
        $proto      = $url["scheme"]."://";
2042
        $addr       = $url["host"];
2043
        if ($url["port"]!="") {
2044
            $addr .= ":".$url["port"];
2045
        }
2046
        $path       = $url["path"];
2047
 
2048
        return 0;
2049
    }
2050
 
539 alex-w 2051
    /**
2052
     * Выгрузка картинок логотипов дистрибутивов
2053
     *
2054
     * @author Alexander Wolf
2055
     * @category Core
2056
     *
2057
     * @param string $path
2058
     * @param string $dist
2059
     * @param array $datafile
2060
     * @return integer
2061
     */
535 alex-w 2062
    public function uploadPicture($path, $dist, $datafile) {
2063
        $folder   = $path.$dist."-orig.png";
2064
        $folderN  = $path.$dist.".png";
2065
        $folderEM = $path.$dist."-em.png";
2066
 
2067
        $distlogo = 0;
2068
        if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
2069
            chmod($folder, 0644);
2070
            list($width, $height) = GetImageSize($folder);
2071
            $percent = 32/$height;
2072
            $newwidth = $width * $percent;
2073
            $newheight = $height * $percent;
2074
 
2075
            $output = ImageCreateTrueColor($newwidth, $newheight);
2076
            $source = ImageCreateFromPNG($folder);
2077
 
2078
            ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
2079
            ImagePNG($output, $folderEM);
2080
 
2081
            $percent = 15/$height;
2082
            $newwidth = $width * $percent;
2083
            $newheight = $height * $percent;
2084
 
2085
            $output = ImageCreateTrueColor($newwidth, $newheight);
2086
 
2087
            ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
2088
            ImagePNG($output, $folderN);
2089
 
2090
            unlink($folder);
2091
            $distlogo = 1;
2092
        }
2093
        return $distlogo;
2094
    }
547 alex-w 2095
 
2096
    /**
2097
     * Показ списка репозиториев
2098
     *
2099
     * @author Alexander Wolf
2100
     * @category Core
2101
     *
2102
     * @param string $name
2103
     * @param string $actor
2104
     * @param string $format
2105
     * @return string
2106
     */
548 alex-w 2107
    public function showRepositoriesList($name, $actor, $format = 'list') {
643 alex-w 2108
        $query  = "SELECT r.*,rt.*,v.version_id,CONCAT(d.distname,' ',v.version,' &#8220;',v.vname,'&#8221;') AS fullname FROM ".$this->prefix."repository r ";
548 alex-w 2109
        $query .= "JOIN ".$this->prefix."rtype rt ON rt.rtype_id=r.rtype_id ";
629 alex-w 2110
        $query .= "JOIN ".$this->prefix."version v ON v.version_id=r.version ";
641 alex-w 2111
        $query .= "JOIN ".$this->prefix."distribution d ON d.dist_id=v.dist_id ";
695 alex-w 2112
        $query .= "ORDER BY v.version_id,rt.rtype_id,r.rep_id ASC";
548 alex-w 2113
        $rq =& $this->db->query($query);
639 alex-w 2114
        $show = "<ul><li class='nomarker'></li>";
630 alex-w 2115
        $splitter = 0;
548 alex-w 2116
        while ($rq->fetchInto($element)) {
630 alex-w 2117
            if ($splitter != $this->secure->checkInt($element["version_id"])) {
2118
                $splitter = $this->secure->checkInt($element["version_id"]);
645 alex-w 2119
                $show .= "</ul><ul><li class='nomarker'><strong>Репозитории для ".$this->secure->checkStr($element["fullname"],1)."</strong></li>";
630 alex-w 2120
            }
634 alex-w 2121
            $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)." (<em>".$this->secure->checkStr($element["rtype"],1)."</em>)</li>\n";
548 alex-w 2122
        }
2123
        $show .= "</ul>";
547 alex-w 2124
        return $show;
2125
    }
2126
 
2127
    /**
558 alex-w 2128
     * Вывод списка типов репозиториев
2129
     *
2130
     * @author Alexander Wolf
2131
     * @category Core
2132
     *
2133
     * @param integer $reptype
2134
     * @param string $name
2135
     * @return string
2136
     */
2137
    public function showRepType($reptype = 0, $name = "") {
2138
        $sRT = $this->secure->checkInt($reptype);
2139
        $sNM = $this->secure->checkStr($name,1);
559 alex-w 2140
        $query = "SELECT * FROM ".$this->prefix."rtype";
558 alex-w 2141
        $rq =& $this->db->query($query);
2142
        $show = "<select name='".$sNM."' id='".$sNM."'>\n";
2143
        while ($rq->fetchInto($element)) {
2144
            if ($element["rtype_id"]==$sRT) {
2145
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."' selected>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
2146
            } else {
2147
                $show .= "<option value='".$this->secure->checkInt($element["rtype_id"])."'>".$this->secure->checkStr($element["rtype"],1)."</option>\n";
2148
            }
2149
        }
2150
        $show .= "</select>";
2151
 
2152
        return $show;
2153
    }
2154
 
623 alex-w 2155
    /**
2156
     * Вывод списка версий дистрибутивов
2157
     *
2158
     * @author Alexander Wolf
2159
     * @category Core
2160
     *
2161
     * @param string $name
2162
     * @param integer $versionID
2163
     * @return string
2164
     */
591 alex-w 2165
    public function showVDList($name, $versionID = 0) {
592 alex-w 2166
        $query  = "SELECT v.version_id, CONCAT(d.distname, ' ', v.version, ' ', v.vname) AS fullname FROM ".$this->prefix."version v ";
591 alex-w 2167
        $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id";
2168
        $rq =& $this->db->query($query);
2169
        $show = "<select name='".$name."' id='".$name."'>\n";
2170
        while ($rq->fetchInto($element)) {
592 alex-w 2171
            if ($element["version_id"]==$versionID) {
2172
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."' selected>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
2173
            } else {
2174
                $show .= "<option value='".$this->secure->checkInt($element["version_id"])."'>".$this->secure->checkStr($element["fullname"],1)."</option>\n";
2175
            }
591 alex-w 2176
        }
2177
        $show .= "</select>";
2178
        return $show;
2179
    }
2180
 
558 alex-w 2181
    /**
547 alex-w 2182
     * Форма создания/редактирвоания репозиториев
2183
     *
2184
     * @author Alexander Wolf
2185
     * @category Core
2186
     *
2187
     * @param integer $repID
2188
     * @param string $info
2189
     * @param string $reptype
2190
     * @return string
2191
     */
594 alex-w 2192
    public function showRepositoriesForm($repID = 0, $info = "") {
556 alex-w 2193
        $sRepID = $this->secure->checkInt($repID);
594 alex-w 2194
        $sInfo  = $this->secure->checkStr($info, 1);        
556 alex-w 2195
        if ($sInfo == "") {
2196
            $sInfo = "Репозиторий";
2197
        }
2198
        if ($sRepID != 0) {
2199
            // Режим редактирования
591 alex-w 2200
            $query  = "SELECT r.*,v.*,d.dist_id,dt.type FROM ".$this->prefix."repository r ";
556 alex-w 2201
            $query .= "JOIN ".$this->prefix."version v ON r.version=v.version_id ";
2202
            $query .= "JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id ";
2203
            $query .= "JOIN ".$this->prefix."dtype dt ON d.disttype=dt.type_id ";
2204
            $query .= "WHERE r.rep_id='".$sRepID."'";
2205
            $rq =& $this->db->query($query);
594 alex-w 2206
            $rq->fetchInto($element);            
556 alex-w 2207
        }
2208
 
594 alex-w 2209
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";        
609 alex-w 2210
        $show .= "<div class='inputbox'><label for='rdist'>Дистрибутив:</label> ".$this->showVDList("rdist",$this->secure->checkInt($element["version_id"]),"innerhtml")."</div>\n";
626 alex-w 2211
        $show .= "<div class='inputbox'><label for='rname'>Название репозитория:</label> <input type='text' name='rname' value=\"".$this->secure->checkStr($element["repname"],1)."\"></div>\n";
2212
        $show .= "<div class='inputbox'><label for='rinfo'>Описание репозитория:</label> <input type='text' name='rinfo' value=\"".$this->secure->checkStr($element["repinfo"],1)."\"></div>\n";
2213
        $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 2214
        $show .= "<div class='inputbox'><label for='rproto'>Протокол доступа:</label> ".$this->showProtoList("rproto",$this->secure->checkInt($element["proto_id"]),"innerhtml")."</div>\n";
588 alex-w 2215
        $show .= "<div class='inputbox'><label for='rhost'>Хост репозитория:</label> ".$this->showHostsList("rhost",$this->secure->checkInt($element["rhost_id"]),"innerhtml")."</div>\n";
604 alex-w 2216
        $show .= "<div class='inputbox'><label for='rfolder'>Корневая папка:</label> ".$this->showFoldersList("rfolder",$this->secure->checkInt($element["rfolder_id"]),"innerhtml")."</div>\n";
558 alex-w 2217
        $show .= "<div class='inputbox'><label for='rtype'>Тип репозитория:</label> ".$this->showRepType($this->secure->checkInt($element["rtype_id"]), "rtype")."</div>\n";
564 alex-w 2218
        $show .= "<div class='inputbox'><label for='rsects'>Секции репозитория:</label> <div class='formwrapper'>".$this->showSectionsList("rsects",$sRepID,"innerhtml")."</div></div>\n";
569 alex-w 2219
        $show .= "<div class='inputbox'><label for='rarchs'>Архитектуры:</label> <div class='formwrapper'>".$this->showArchList("rarchs",$sRepID,"innerhtml")."</div></div>\n";
613 alex-w 2220
        $show .= "<div class='inputbox'><label for='rscheme'>Схема репозитория:</label> ".$this->showSchemeList("rscheme",$this->secure->checkInt($element["scheme_id"]),"innerhtml")."</div>\n";
595 alex-w 2221
        $show .= "<div class='inputbox'><label for='rsign'>Подпись репозитория:</label> ".$this->showSignsList("rsign",$this->secure->checkInt($element["sign_id"]),"innerhtml")."</div>\n";
556 alex-w 2222
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
593 alex-w 2223
 
547 alex-w 2224
        return $show;
2225
    }
598 alex-w 2226
 
2227
    /**
2228
     * Добавление нового репозитория
2229
     *
2230
     * @author Alexander Wolf
2231
     * @category Core
2232
     *
2233
     * @param integer $verionID
2234
     * @param string $rname
2235
     * @param string $rinfo
2236
     * @param string $rkey
2237
     * @param integer $proto
2238
     * @param integer $rhost
2239
     * @param integer $rfolder
2240
     * @param integer $rtype
2241
     * @param array $sections
2242
     * @param array $arch
2243
     * @param integer $scheme
2244
     * @param integer $sign
2245
     * @return array
2246
     */
612 alex-w 2247
    public function addRepository($verionID, $rname, $rinfo, $rkey, $proto, $rhost, $rfolder, $rtype, $scheme, $sign, $sections, $arch) {
598 alex-w 2248
        $result = array();
2249
        $sVersionID     = $this->secure->checkInt($verionID);
2250
        $sRName         = $this->secure->checkStr($rname);
2251
        $sRInfo         = $this->secure->checkStr($rinfo);
2252
        $sRKey          = $this->secure->checkStr($rkey);
2253
        $sProto         = $this->secure->checkInt($proto);
2254
        $sRHost         = $this->secure->checkInt($rhost);
2255
        $sRFolder       = $this->secure->checkInt($rfolder);
2256
        $sRType         = $this->secure->checkInt($rtype);
2257
        $sRScheme       = $this->secure->checkInt($scheme);
2258
        $sRSign         = $this->secure->checkInt($sign);
2259
 
602 alex-w 2260
        $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 2261
        $rq =& $this->db->query($query);
2262
 
2263
        $query = "SELECT rep_id FROM ".$this->prefix."repository ORDER BY rep_id DESC LIMIT 0, 1";
2264
        $rq =& $this->db->query($query);
2265
        $rq->fetchInto($repository);
2266
 
2267
        for($i=0;$i<count($sections);$i++) {
2268
            $query = "INSERT INTO ".$this->prefix."sect2rep SET rep_id='".$repository["rep_id"]."', sect_id='".$sections[$i]."'";
2269
            $rq =& $this->db->query($query);
2270
        }
2271
 
2272
        for($i=0;$i<count($arch);$i++) {
2273
            $query = "INSERT INTO ".$this->prefix."arch2rep SET rep_id='".$repository["rep_id"]."', arch_id='".$arch[$i]."'";
2274
            $rq =& $this->db->query($query);
2275
        }
2276
 
2277
        if (PEAR::isError($this->db)) {
2278
            $result["ERR"] = 1;
2279
            $result["ERRINFO"] = $this->db->getMessage();
2280
        } else {
2281
            $result["ERR"] = 0;
2282
        }
2283
 
2284
        return $result;
2285
    }
618 alex-w 2286
 
2287
    /**
2288
     * Обновление информации о репозитории
2289
     *
2290
     * @author Alexander Wolf
2291
     * @category Core
2292
     *
2293
     * @param integer $repID
2294
     * @param integer $verionID
2295
     * @param string $rname
2296
     * @param string $rinfo
2297
     * @param string $rkey
2298
     * @param integer $proto
2299
     * @param integer $rhost
2300
     * @param integer $rfolder
2301
     * @param integer $rtype
2302
     * @param array $sections
2303
     * @param array $arch
2304
     * @param integer $scheme
2305
     * @param integer $sign
2306
     * @return array
2307
     */
2308
    public function updateRepository($repID, $verionID, $rname, $rinfo, $rkey, $proto, $rhost, $rfolder, $rtype, $scheme, $sign, $sections, $arch) {
2309
        $result = array();
2310
        $sRepID         = $this->secure->checkInt($repID);
2311
        $sVersionID     = $this->secure->checkInt($verionID);
2312
        $sRName         = $this->secure->checkStr($rname);
2313
        $sRInfo         = $this->secure->checkStr($rinfo);
2314
        $sRKey          = $this->secure->checkStr($rkey);
2315
        $sProto         = $this->secure->checkInt($proto);
2316
        $sRHost         = $this->secure->checkInt($rhost);
2317
        $sRFolder       = $this->secure->checkInt($rfolder);
2318
        $sRType         = $this->secure->checkInt($rtype);
2319
        $sRScheme       = $this->secure->checkInt($scheme);
2320
        $sRSign         = $this->secure->checkInt($sign);
2321
 
2322
        $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."'";
2323
        $rq =& $this->db->query($query);
2324
 
2325
        $query = "DELETE FROM ".$this->prefix."sect2rep WHERE rep_id='".$sRepID."'";
2326
        $rq =& $this->db->query($query);
2327
        for($i=0;$i<count($sections);$i++) {
2328
            $query = "INSERT INTO ".$this->prefix."sect2rep SET rep_id='".$sRepID."', sect_id='".$sections[$i]."'";
2329
            $rq =& $this->db->query($query);
2330
        }
2331
 
2332
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE rep_id='".$sRepID."'";
2333
        $rq =& $this->db->query($query);
2334
        for($i=0;$i<count($arch);$i++) {
2335
            $query = "INSERT INTO ".$this->prefix."arch2rep SET rep_id='".$sRepID."', arch_id='".$arch[$i]."'";
2336
            $rq =& $this->db->query($query);
2337
        }
2338
 
2339
        if (PEAR::isError($this->db)) {
2340
            $result["ERR"] = 1;
2341
            $result["ERRINFO"] = $this->db->getMessage();
2342
        } else {
2343
            $result["ERR"] = 0;
2344
        }
2345
 
2346
        return $result;
2347
    }
2348
 
2349
    /**
2350
     * Удаление информации о репозитории
2351
     *
2352
     * @author Alexander Wolf
2353
     * @category Core
2354
     *
2355
     * @param integer $repID
2356
     * @return array
2357
     */
2358
    public function dropRepository($repID) {
2359
        $result = array();
2360
        $sRepID         = $this->secure->checkInt($repID);
2361
 
2362
        // Удаление репозитория
2363
        $query = "DELETE FROM ".$this->prefix."repository WHERE rep_id='".$sRepID."'";
2364
        $rq =& $this->db->query($query);
2365
        if (PEAR::isError($this->db)) {
2366
            $result["ERR"] = 1;
2367
            $result["ERRINFO"] = $this->db->getMessage();
2368
        } else {
2369
            $result["ERR"] = 0;
2370
        }
2371
 
2372
        // Удаление секций репозитория
2373
        $query = "DELETE FROM ".$this->prefix."sect2rep WHERE rep_id='".$sRepID."'";
2374
        $rq =& $this->db->query($query);
2375
        if (PEAR::isError($this->db)) {
2376
            $result["ERR"] = 1;
2377
            $result["ERRINFO"] = $this->db->getMessage();
2378
        } else {
2379
            $result["ERR"] = 0;
2380
        }
2381
 
2382
        // Удаление архитектур репозитория
2383
        $query = "DELETE FROM ".$this->prefix."arch2rep WHERE rep_id='".$sRepID."'";
2384
        $rq =& $this->db->query($query);
2385
        if (PEAR::isError($this->db)) {
2386
            $result["ERR"] = 1;
2387
            $result["ERRINFO"] = $this->db->getMessage();
2388
        } else {
2389
            $result["ERR"] = 0;
2390
        }
2391
 
2392
        return $result;
2393
    }
684 alex-w 2394
 
685 alex-w 2395
    /**
2396
     * Вывод списка настроек
2397
     *
2398
     * @author Alexander Wolf
2399
     * @category Core
2400
     *
2401
     * @param string $name
2402
     * @param string $actor
2403
     * @param string $format
2404
     * @return string
2405
     */
684 alex-w 2406
    public function showSettingsList($name, $actor, $format = 'list') {
2407
        $query = "SELECT * FROM ".$this->prefix."settings";
2408
        $rq =& $this->db->query($query);
2409
        $show = "<ul>\n";
688 alex-w 2410
        $show .= "<li><a href='".$actor."?mode=".$name."&action=update-password' class='edit'>Изменить пароль доступа</a></li>\n";
684 alex-w 2411
        $show .= "</ul>";
685 alex-w 2412
 
2413
        return $show;
684 alex-w 2414
    }
688 alex-w 2415
 
2416
    /**
2417
     * Форма обновления пароля
2418
     *
2419
     * @author Alexander Wolf
2420
     * @category Core
2421
     *
2422
     * @return string
2423
     */
2424
    public function showUpdatePasswordForm() {
2425
        $show .= "<fieldset><legend>Обновление пароля доступа</legend>\n";
2426
        $show .= "<div class='inputbox'><label for='oword'>Текущий пароль:</label> <input type='password' name='oword' value=''></div>\n";
2427
        $show .= "<div class='inputbox'><label for='nword'>Новый пароль:</label> <input type='password' name='nword' value=''></div>\n";
2428
        $show .= "<div class='inputbox'><label for='again'>Повторно:</label> <input type='password' name='again' value=''></div>\n";
2429
        $show .= "<input type='submit' value=' Войти '>\n";
2430
        $show .= "</fieldset>\n\n";
2431
 
2432
        return $show;
2433
    }
560 alex-w 2434
 
304 alex-w 2435
}
2436
 
356 alex-w 2437
?>