Хранилища Subversion ant

Редакция

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