Хранилища Subversion ant

Редакция

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

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