Хранилища Subversion ant

Редакция

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