Хранилища Subversion ant

Редакция

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

Редакция Автор № строки Строка
304 alex-w 1
<?php
2
 
3
/**
4
 *  
5
 *  Codename: ant-ng - generator of sources.list for Debian and
6
 *  distributives, based on Debian
7
 *  http://alex-w.org.ru/p/antng/
8
 *
9
 *  Copyright (c) 2009 Alexander Wolf
10
 *  Dual licensed under the MIT and GNU LGPL licenses.
11
 *  http://alex-w.org.ru/p/antng/license
12
 *
13
 */
14
 
15
class Core {
308 alex-w 16
    protected $db       = NULL;
17
    protected $prefix   = NULL;
313 alex-w 18
    protected $secure   = NULL;    
359 alex-w 19
    protected $cookie   = NULL;
304 alex-w 20
 
463 alex-w 21
    /**
22
     * Конструктор класса Core - ядро генератора
23
     *
24
     * @author Alexander Wolf
25
     * @category Core
26
     *
27
     * @param string $database
28
     * @param string $prefix
29
     * @param object $secure
30
     * @param string $cookie
31
     */
368 alex-w 32
    public function __construct($database, $prefix, $secure, $cookie) {
308 alex-w 33
        $this->db       = $database;
34
        $this->prefix   = $prefix;
359 alex-w 35
        $this->secure   = $secure;
36
        $this->cookie   = $cookie;
307 alex-w 37
    }
38
 
463 alex-w 39
    /**
40
     * Получение данных о настройке
41
     *
42
     * @author Alexander Wolf
43
     * @category Core
44
     *
45
     * @param string $attr
46
     * @return array
47
     */
368 alex-w 48
    public function getOption($attr) {
308 alex-w 49
        $result = array();
315 alex-w 50
        $query = "SELECT optvalue FROM ".$this->prefix."settings WHERE opt='".$this->secure->checkStr($attr)."'";
314 alex-w 51
        $rq =& $this->db->query($query);
308 alex-w 52
        if ($rq->numRows()!=0) {
53
            $rq->fetchInto($element);
54
            $result["ERR"] = 0;
55
            $result["OptValue"] = $element["optvalue"];
56
        } else {
57
            $result["ERR"] = 1;
58
            $result["ERRINFO"] = "Empty result";
59
        }
60
        return $result;
61
    }
62
 
463 alex-w 63
    /**
64
     * Установка данных о настройке
65
     *
66
     * @author Alexander Wolf
67
     * @category Core
68
     *
69
     * @param string $attr
70
     * @param string $value
71
     * @return array
72
     */
368 alex-w 73
    public function setOption($attr, $value) {
359 alex-w 74
        $result = array();
75
 
76
        if ($attr != "passwd") {
77
            $sValue = $this->secure->checkStr($value);
78
        } else {
79
            $sValue = $value;
80
        }
81
 
82
        $query = "UPDATE ".$this->prefix."settings SET optvalue='".$sValue."' WHERE opt='".$attr."'";
83
        $rq =& $this->db->query($query);
84
        if (PEAR::isError($this->db)) {
85
            $result["ERR"] = 1;
86
            $result["ERRINFO"] = $this->db->getMessage();
87
        } else {
88
            $result["ERR"] = 0;
89
        }
90
 
91
        return $result;
92
    }
93
 
463 alex-w 94
    /**
95
     * Создание настройки
96
     *
97
     * @author Alexander Wolf
98
     * @category Core
99
     *
100
     * @param string $attr
101
     * @param string $value
102
     * @return array
103
     */
368 alex-w 104
    public function addOption($attr, $value) {
359 alex-w 105
        $result = array();
106
        $sValue = $this->secure->checkStr($value);
107
 
108
        $query = "INSERT INTO ".$this->prefix."settings SET opt='".$attr."', optvalue='".$sValue."'";
109
        $rq =& $this->db->query($query);
110
        if (PEAR::isError($this->db)) {
111
            $result["ERR"] = 1;
112
            $result["ERRINFO"] = $this->db->getMessage();
113
        } else {
114
            $result["ERR"] = 0;
115
        }
116
 
117
        return $result;
118
    }
463 alex-w 119
 
120
    /**
467 alex-w 121
     * Получение и отображение списка дистрибутвов
463 alex-w 122
     *
123
     * @author Alexander Wolf
124
     * @category Core
125
     * @deprecated may be deprecated XXX
126
     *
127
     * @param string $name
128
     * @param string $heads
129
     * @param string $info
130
     * @param string $format
131
     * @return string
132
     */
393 alex-w 133
    public function showDistributionList($name, $heads = "", $info = "", $format = 'html') {
315 alex-w 134
        $query = "SELECT * FROM ".$this->prefix."distribution ORDER BY dist_id ASC";
317 alex-w 135
        $rq =& $this->db->query($query);
315 alex-w 136
        switch ($format) {
137
            case 'html':
394 alex-w 138
                $show  = "<fieldset><legend>".$heads."</legend>\n<select id='".$name."' name='".$name."'>\n";
390 alex-w 139
                $show .= "<option value=''>".$info."</option>\n";
315 alex-w 140
                while ($rq->fetchInto($element)) {
141
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
142
                }
317 alex-w 143
                $show .= "</select></fieldset>";
315 alex-w 144
                break;
145
            case 'json':
317 alex-w 146
                $show = '[{value:"",text:"'.$info.'"}';                
315 alex-w 147
                while ($rq->fetchInto($element)) {
148
                    $show .= ',{value:"'.$this->secure->checkInt($element["dist_id"]).'",text:"'.$this->secure->checkStr($element["distname"],1).'"}';
149
                }
150
                $show .= ']';
151
                break;
504 alex-w 152
            case 'innerhtml':
153
                $show = "<select id='".$name."' name='".$name."'>\n";
154
                while ($rq->fetchInto($element)) {
155
                    $show .= "<option value='".$this->secure->checkInt($element["dist_id"])."'>".$this->secure->checkStr($element["distname"],1)."</option>\n";
156
                }
157
                $show .= "</select>";
158
                break;
506 alex-w 159
            case 'list':
160
                $show = "<ul>";
161
                while ($rq->fetchInto($element)) {
509 alex-w 162
                    $show .= "<li>[<a href='".$heads."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["dist_id"])."'>править</a>][<a href='".$heads."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["dist_id"])."'>удалить</a>] ".$this->secure->checkStr($element["distname"],1)."</li>\n";
506 alex-w 163
                }
164
                $show .= "</ul>";
165
                break;
315 alex-w 166
        }
167
        return $show;
168
    }
169
 
463 alex-w 170
    /**
171
     * Получение названия дистрибутива
172
     *
173
     * @author Alexander Wolf
174
     * @category Core
175
     *
176
     * @param integer $distID
177
     * @return array
178
     */
368 alex-w 179
    public function getDistName($distID) {
315 alex-w 180
        $result = array();
181
        $query = "SELECT distname FROM ".$this->prefix."distribution WHERE dist_id='".$this->secure->checkInt($distID)."'";
182
        $rq =& $this->db->query($query);
183
        if (PEAR::isError($this->db)) {
184
            $result["ERR"] = 1;
185
            $result["ERRINFO"] = $this->db->getMessage();
186
        } else {
187
            $rq->fetchInto($element);
188
            $result["ERR"] = 0;
189
            $result["DistName"] = $this->secure->checkStr($element["distname"],1);
190
        }
191
 
192
        return $result;
193
    }
194
 
463 alex-w 195
    /**
196
     * Получение названия программы, ее версии и описания
197
     *
198
     * @author Alexander Wolf
199
     * @category Core
200
     *
201
     * @param string $attr
202
     * @return string
203
     */
383 alex-w 204
    public function getEngineAttr($attr = 'codename') {
205
        $cname = $this->getOption($attr);
382 alex-w 206
        return $this->secure->checkStr($cname["OptValue"],1);
381 alex-w 207
    }
208
 
463 alex-w 209
    /**
210
     * Получение и отображение списка версий дистрибутива
211
     *
212
     * @author Alexander Wolf
213
     * @category Core
214
     *
215
     * @param string $name
216
     * @param integer $distID
217
     * @param string $format
218
     * @return string
219
     */
509 alex-w 220
    public function showDistVersionsList($name, $distID, $format = 'html', $actor = '') {
316 alex-w 221
        $distname = $this->getDistName($distID);
509 alex-w 222
        if ($distID == 0) {
223
            $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";
224
        } else {
225
            $query = "SELECT * FROM ".$this->prefix."version WHERE dist_id='".$this->secure->checkInt($distID)."' ORDER BY version ASC";
226
        }
317 alex-w 227
        $rq =& $this->db->query($query);
315 alex-w 228
        switch ($format) {
229
            case 'html':
394 alex-w 230
                $show  = "<fieldset><legend>Версии ".$distname["DistName"]."</legend>\n<select id='".$name."' name='".$name."'>\n";
231
                $show .= "<option value=''>Выбери версию ".$distname["DistName"]."</option>\n";
315 alex-w 232
                while ($rq->fetchInto($element)) {
316 alex-w 233
                    $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 234
                }
317 alex-w 235
                $show .= "</select></fieldset>";
315 alex-w 236
                break;
237
            case 'json':
317 alex-w 238
                $show = '[{value:"",text:"Выбери версию '.$distname["DistName"].'"}';                
315 alex-w 239
                while ($rq->fetchInto($element)) {
316 alex-w 240
                    $show .= ',{value:"'.$this->secure->checkInt($element["version_id"]).'",text:"'.$this->secure->checkStr($element["version"],1).' '.$this->secure->checkStr($element["vname"],1).'"}';
315 alex-w 241
                }
242
                $show .= ']';
243
                break;
509 alex-w 244
            case 'list':
245
                $show = "<ul>\n";
246
                while ($rq->fetchInto($element)) {
247
                    $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$this->secure->checkInt($element["version_id"])."'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$this->secure->checkInt($element["version_id"])."'>удалить</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";
248
                }
249
                $show .= "</ul>";
250
                break;
315 alex-w 251
        }
252
        return $show;
253
    }
254
 
463 alex-w 255
    /**
256
     * Получение и отображение списка секций основного (официального) репозитория
257
     *
258
     * @author Alexander Wolf
259
     * @category Core
260
     *
261
     * @param integer $version
262
     * @param string $format
263
     * @return string
264
     */
368 alex-w 265
    public function showBranchesList($version, $format = 'html') {
317 alex-w 266
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='1'";
267
        $rq =& $this->db->query($query);
268
        $rq->fetchInto($types);
269
        $query  = "SELECT s.*,t.rtype FROM ".$this->prefix."section s ";
270
        $query .= "JOIN ".$this->prefix."sect2rep l ON s.sect_id=l.sect_id ";
271
        $query .= "JOIN ".$this->prefix."repository r ON r.rep_id=l.rep_id ";
272
        $query .= "JOIN ".$this->prefix."rtype t ON r.rtype_id=t.rtype_id ";
273
        $query .= "WHERE t.rtype_id='1' AND r.version='".$this->secure->checkInt($version)."'";
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') {
406 alex-w 303
        $query  = "SELECT rtype FROM ".$this->prefix."rtype WHERE rtype_id='".$this->secure->checkInt($reptype)."'";
317 alex-w 304
        $rq =& $this->db->query($query);
305
        $rq->fetchInto($types);
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':
310
                $show = "<fieldset><legend>".$this->secure->checkStr($types["rtype"],1)."</legend>\n";
311
                while ($rq->fetchInto($types)) {
320 alex-w 312
                    $show .= "<div class='repository'><input type='checkbox' name='repository[]' value='".$element["rep_id"]."'> ".$this->secure->checkStr($element["repname"],1)." &mdash; ".$this->secure->checkStr($element["repinfo"],1)."</div>\n";
317 alex-w 313
                }
314
                $show .= "</fieldset>\n";
315
                break;
316
            case 'json':
317
                //TODO Доделать JSON-вывод списка репозиториев
318
                break;
319
        }
318 alex-w 320
 
321
        return $show;
317 alex-w 322
    }
323
 
463 alex-w 324
    /**
325
     * Добавление поддержки нового apt-дистрибутива
326
     *
327
     * @author Alexander Wolf
328
     * @category Core
329
     *
330
     * @param string $distname
331
     * @param integer $disttype
332
     * @param string $distua
333
     * @param byte $distlogo
334
     * @return array
335
     */
514 alex-w 336
    public function addDistribution($distname, $disttype, $distua = '', $distlogo = 0) {
321 alex-w 337
        $result = array();
516 alex-w 338
        $sDName = $this->secure->checkStr($distname,1);
321 alex-w 339
        $sDType = $this->secure->checkInt($disttype);
516 alex-w 340
        $sDUAgt = $this->secure->checkStr($distua,1);
514 alex-w 341
        $sDLogo = $this->secure->checkInt($distlogo);
321 alex-w 342
 
343
        $query = "INSERT INTO ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."'";
344
        $rq =& $this->db->query($query);
345
        if (PEAR::isError($this->db)) {
346
            $result["ERR"] = 1;
347
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 348
        } else {            
321 alex-w 349
            $result["ERR"] = 0;
350
        }
351
 
352
        return $result;
353
    }
354
 
463 alex-w 355
    /**
514 alex-w 356
     * Обновление информации о дистрибутиве
357
     *
358
     * @author Alexander Wolf
359
     * @category Core
360
     *
361
     * @param integer $distID
362
     * @param string $distname
363
     * @param integer $disttype
364
     * @param string $distua
365
     * @param integer $distlogo
366
     * @return array
367
     */
538 alex-w 368
    public function updateDistribution($distID, $distname, $disttype, $distua, $distlogo = 0) {
514 alex-w 369
        $result = array();
370
        $sDID   = $this->secure->checkInt($distID);
516 alex-w 371
        $sDName = $this->secure->checkStr($distname,1);
514 alex-w 372
        $sDType = $this->secure->checkInt($disttype);
516 alex-w 373
        $sDUAgt = $this->secure->checkStr($distua,1);
514 alex-w 374
        $sDLogo = $this->secure->checkInt($distlogo);
375
 
538 alex-w 376
        if ($sDLogo!=0) {
377
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."', distlogo='".$sDLogo."' WHERE dist_id='".$sDID."'";
378
        } else {
379
            $query = "UPDATE ".$this->prefix."distribution SET distname='".$sDName."', distua='".$sDUAgt."', disttype='".$sDType."' WHERE dist_id='".$sDID."'";
380
        }
514 alex-w 381
        $rq =& $this->db->query($query);
382
        if (PEAR::isError($this->db)) {
383
            $result["ERR"] = 1;
384
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 385
        } else {            
514 alex-w 386
            $result["ERR"] = 0;
387
        }
388
 
389
        return $result;
390
    }
391
 
392
    /**
393
     * Удаление информации о дистрибутиве
394
     *
395
     * @author Alexander Wolf
396
     * @category Core
397
     *
398
     * @param integer $distID
399
     * @return array
400
     */
401
    public function dropDistribution($distID) {
402
        $result = array();
403
        $sDID   = $this->secure->checkInt($distID);
404
 
405
        // Удаление дистрибутива
406
        $query = "DELETE FROM ".$this->prefix."distribution WHERE dist_id='".$sDID."'";
407
        $rq =& $this->db->query($query);
408
        if (PEAR::isError($this->db)) {
409
            $result["ERR"] = 1;
410
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 411
        } else {            
514 alex-w 412
            $result["ERR"] = 0;
413
        }
414
 
415
        // Удаление версий дистрибутива
416
        $query = "DELETE FROM ".$this->prefix."version WHERE dist_id='".$sDID."'";
417
        $rq =& $this->db->query($query);
418
        if (PEAR::isError($this->db)) {
419
            $result["ERR"] = 1;
420
            $result["ERRINFO"] = $this->db->getMessage();
519 alex-w 421
        } else {            
514 alex-w 422
            $result["ERR"] = 0;
423
        }
424
 
425
        return $result;
426
    }
427
 
428
    /**
463 alex-w 429
     * Добавление поддержки новой версии apt-дистрибутива
430
     *
431
     * @author Alexander Wolf
432
     * @category Core
433
     *
434
     * @param integer $distID
435
     * @param integer $version
436
     * @param string $vname
437
     * @param integer $vcodename
438
     * @return array
439
     */
368 alex-w 440
    public function addDistVersion($distID, $version, $vname = "", $vcodename = "") {
356 alex-w 441
        $result = array();
463 alex-w 442
        $sDistID    = $this->secure->checkInt($distID);
516 alex-w 443
        $sDVersion  = $this->secure->checkStr($version,1);
444
        $sDVName    = $this->secure->checkStr($vname,1);
445
        $sDVCName   = $this->secure->checkStr($vcodename,1);
356 alex-w 446
 
447
        $query = "INSERT INTO ".$this->prefix."version SET dist_id='".$sDistID."', vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."'";
448
        $rq =& $this->db->query($query);
449
        if (PEAR::isError($this->db)) {
450
            $result["ERR"] = 1;
451
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 452
        } else {            
356 alex-w 453
            $result["ERR"] = 0;
454
        }
455
 
456
        return $result;
457
    }
358 alex-w 458
 
463 alex-w 459
    /**
514 alex-w 460
     * Редактирование информации о версии дистрибутива
461
     *
462
     * @author Alexander Wolf
463
     * @category Core
464
     *
465
     * @param integer $versionID
466
     * @param string $version
467
     * @param string $vname
468
     * @param string $vcodename
469
     * @return array
470
     */
471
    public function updateDistVersion($versionID, $version, $vname = "", $vcodename = "") {
472
        $result = array();
473
        $sVersID    = $this->secure->checkInt($versionID);
516 alex-w 474
        $sDVersion  = $this->secure->checkStr($version,1);
475
        $sDVName    = $this->secure->checkStr($vname,1);
476
        $sDVCName   = $this->secure->checkStr($vcodename,1);
514 alex-w 477
 
478
        $query = "UPDATE ".$this->prefix."version SET vname='".$sDVName."', version='".$sDVersion."', vcodename='".$sDVCName."' WHERE version_id='".$sVersID."'";
479
        $rq =& $this->db->query($query);
480
        if (PEAR::isError($this->db)) {
481
            $result["ERR"] = 1;
482
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 483
        } else {            
514 alex-w 484
            $result["ERR"] = 0;
485
        }
486
 
487
        return $result;
488
    }
489
 
490
    /**
491
     * Удаление информации о версии дистрибутива
492
     *
493
     * @author Alexander Wolf
494
     * @category Core
495
     *
496
     * @param integer $versionID
497
     * @return array
498
     */
499
    public function dropDistVersion($versionID) {
500
        $result = array();
501
        $sVersID    = $this->secure->checkInt($versionID);
502
 
503
        // Удаление версии дистрибутива
504
        $query = "DELETE FROM ".$this->prefix."version WHERE version_id='".$sVersID."'";
505
        $rq =& $this->db->query($query);
506
        if (PEAR::isError($this->db)) {
507
            $result["ERR"] = 1;
508
            $result["ERRINFO"] = $this->db->getMessage();
515 alex-w 509
        } else {            
514 alex-w 510
            $result["ERR"] = 0;
511
        }
512
 
513
        // Удаление репозиториев этой версии дистрибутива
514
        $query = "DELETE FROM ".$this->prefix."repository WHERE version='".$sVersID."'";
515
        $rq =& $this->db->query($query);
516
        if (PEAR::isError($this->db)) {
517
            $result["ERR"] = 1;
518
            $result["ERRINFO"] = $this->db->getMessage();
517 alex-w 519
        } else {            
514 alex-w 520
            $result["ERR"] = 0;
521
        }
522
 
523
        return $result;
524
    }
525
 
526
    /**
463 alex-w 527
     * Отображение типа дистрибутива
528
     *
529
     * @author Alexander Wolf
530
     * @category Core
531
     *
532
     * @param string $name
533
     * @param byte $type
534
     * @return string
535
     */
368 alex-w 536
    public function showDistTypeForm($name = "dtype",$type = 0) {
329 alex-w 537
        $query = "SELECT * FROM ".$this->prefix."dtype";
538
        $rq =& $this->db->query($query);
539
        $show = "<select name='".$name."' id='".$name."'>\n";
540
        while ($rq->fetchInto($element)) {
347 alex-w 541
            if ($element["type_id"] == $type) {
542
                $show .= "<option value='".$element["type_id"]."' selected>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 543
            } else {
347 alex-w 544
                $show .= "<option value='".$element["type_id"]."'>".$this->secure->checkStr($element["type"],1)."</option>\n";
329 alex-w 545
            }
546
        }
547
        $show .= "</select>";
548
 
549
        return $show;
550
    }
551
 
463 alex-w 552
    /**
553
     * Отображение формы создания и редактирования apt-дистрибутива
554
     *
555
     * @author Alexander Wolf
556
     * @category Core
557
     *
558
     * @param integer $distID
559
     * @return string
560
     */
511 alex-w 561
    public function showDistributionForm($distID = 0, $info = '') {
329 alex-w 562
        $sDistID = $this->secure->checkInt($distID);
511 alex-w 563
        $sInfo = $this->secure->checkStr($info, 1);
564
        if ($sInfo == "") {
565
            $sInfo = "Дистрибутив";
566
        }
329 alex-w 567
        if ($sDistID != 0) {
568
            // Режим редактирования
569
            $query = "SELECT * FROM ".$this->prefix."distribution WHERE dist_id='".$sDistID."'";
570
            $rq =& $this->db->query($query);
571
            $rq->fetchInto($element);
572
        }
573
 
574
        if ($element["distlogo"] == 1) {
380 alex-w 575
            $image = "<img src='./img/d/".$this->secure->checkStr($element["distua"],1).".png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."' title='Логотип дистрибутива ".$this->secure->checkStr($element["distname"],1)."'>";
329 alex-w 576
        } else {
380 alex-w 577
            $image = "<img src='./img/d/empty-logo.png' width='32' height='32' id='adm-dist-logo' alt='Логотип дистрибутива' title='Логотип дистрибутива не загружен'>";
329 alex-w 578
        }
579
 
511 alex-w 580
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
350 alex-w 581
        $show .= "<div class='inputbox'><label for='dname'>Название дистрибутива:</label> <input type='text' name='dname' id='dname' value='".$this->secure->checkStr($element["distname"],1)."'></div>\n";
582
        $show .= "<div class='inputbox'><label for='dua'>UA дистрибутива:</label> <input type='text' name='dua' id='dua' value='".$this->secure->checkStr($element["distua"],1)."'></div>\n";
518 alex-w 583
        $show .= "<div class='inputbox'><label for='dtype'>Тип дистрибутива:</label> ".$this->showDistTypeForm("dtype",$element["disttype"])."</div>\n";
348 alex-w 584
        $show .= "<div class='inputbox'><table><tr><td class='td-name'>Логотип дистрибутива:</td>\n";
329 alex-w 585
        $show .= "<td>".$image."</td>\n<td><input type='file' name='distlogo'></td>\n</tr></table>\n</div>\n";
350 alex-w 586
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
329 alex-w 587
 
588
        return $show;
589
    }
590
 
358 alex-w 591
    // sourses.list
423 alex-w 592
    public function showSourcesList($distID,$versID,$sectIDs,$repIDs) {
593
       //TODO Написать генератор sources.list       
358 alex-w 594
    }
522 alex-w 595
 
463 alex-w 596
    /**
522 alex-w 597
     * Показывает список секций
598
     *
599
     * @author Alexander Wolf
600
     * @category Core
601
     *
602
     * @param string $name
603
     * @param string $actor
604
     * @return string
605
     */
606
    public function showSectionsList($name, $actor) {
607
        $query = "SELECT * FROM ".$this->prefix."section";
608
        $rq =& $this->db->query($query);
609
        $show = "<ul>\n";
610
        while ($rq->fetchInto($element)) {
611
            $show .= "<li>[<a href='".$actor."?mode=".$name."&action=edit&uuid=".$element["sect_id"]."'>править</a>][<a href='".$actor."?mode=".$name."&action=delete&uuid=".$element["sect_id"]."'>удалить</a>] ".$this->secure->checkStr($element["secname"],1)."</li>\n";
612
        }
613
        $show .= "</ul>";
614
 
615
        return $show;
616
    }
617
 
523 alex-w 618
    /**
619
     * Вывод формы редактирования/добавления секций
620
     *
621
     * @author Alexander Wolf
622
     * @category Core
623
     *
624
     * @param integer $sectionID
625
     * @param string $info
626
     * @return string
627
     */
628
    public function showSectionsForm($sectionID = 0, $info = "") {
522 alex-w 629
        $sSectID = $this->secure->checkInt($sectionID);
630
        $sInfo = $this->secure->checkStr($info, 1);
631
        if ($sInfo == "") {
632
            $sInfo = "Секция";
633
        }
634
        if ($sSectID != 0) {
635
            // Режим редактирования
636
            $query = "SELECT * FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
637
            $rq =& $this->db->query($query);
638
            $rq->fetchInto($element);
639
        }
640
 
641
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
642
        $show .= "<div class='inputbox'><label for='sname'>Название секции:</label> <input type='text' name='sname' id='sname' value='".$this->secure->checkStr($element["secname"],1)."'></div>\n";
643
        $show .= "<div class='inputbox'><label for='sinfo'>Описание секции:</label> <input type='text' name='sinfo' id='sinfo' value='".$this->secure->checkStr($element["sectinfo"],1)."'></div>\n";
644
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div>\n</fieldset>\n";
645
 
646
        return $show;
647
    }
648
 
649
    /**
523 alex-w 650
     * Обновление информации о секции
651
     *
652
     * @author Alexander Wolf
653
     * @category Core
654
     *
655
     * @param integer $sectionID
656
     * @param string $sname
657
     * @param string $sinfo
658
     * @return array
659
     */
660
    public function updateSection($sectionID, $sname, $sinfo = "") {
661
        $result = array();
662
        $sSectID    = $this->secure->checkInt($sectionID);
663
        $sSName     = $this->secure->checkStr($sname,1);
664
        $sSInfo     = $this->secure->checkStr($sinfo,1);
665
 
666
        $query = "UPDATE ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."' WHERE sect_id='".$sSectID."'";
667
        $rq =& $this->db->query($query);
668
        if (PEAR::isError($this->db)) {
669
            $result["ERR"] = 1;
670
            $result["ERRINFO"] = $this->db->getMessage();
671
        } else {
672
            $result["ERR"] = 0;
673
        }
674
 
675
        return $result;
676
    }
677
 
678
    /**
679
     * Удаление информации о секции
680
     *
681
     * @author Alexander Wolf
682
     * @category Core
683
     *
684
     * @param integer $sectionID
685
     * @return array
686
     */
687
    public function dropSection($sectionID) {
688
        $result = array();
689
        $sSectID    = $this->secure->checkInt($sectionID);
690
 
691
        // Удаление секции
692
        $query = "DELETE FROM ".$this->prefix."section WHERE sect_id='".$sSectID."'";
693
        $rq =& $this->db->query($query);
694
        if (PEAR::isError($this->db)) {
695
            $result["ERR"] = 1;
696
            $result["ERRINFO"] = $this->db->getMessage();
697
        } else {
698
            $result["ERR"] = 0;
699
        }
700
 
701
        return $result;
702
    }
703
 
704
    /**
705
     * Добавление новой секции
706
     *
707
     * @author Alexander Wolf
708
     * @category Core
709
     *
710
     * @param string $sname
711
     * @param string $sinfo
712
     * @return array
713
     */
714
    public function addSection($sname, $sinfo = "") {
715
        $result = array();
716
        $sSName = $this->secure->checkStr($sname,1);
717
        $sSInfo = $this->secure->checkStr($sinfo,1);
718
 
719
        $query = "INSERT INTO ".$this->prefix."section SET secname='".$sSName."', sectinfo='".$sSInfo."'";
720
        $rq =& $this->db->query($query);
721
        if (PEAR::isError($this->db)) {
722
            $result["ERR"] = 1;
723
            $result["ERRINFO"] = $this->db->getMessage();
724
        } else {
725
            $result["ERR"] = 0;
726
        }
727
 
728
        return $result;
729
    }
730
 
731
    /**
463 alex-w 732
     * Проверка пароля (из формы авторизации)
733
     *
734
     * @author Alexander Wolf
735
     * @category Core
736
     *
737
     * @param string $word
738
     * @return array
739
     */
368 alex-w 740
    public function checkSign($word) {
359 alex-w 741
        $result = array();
742
 
743
        $sHash = $this->secure->encryptStr($word);
744
        $pwd   = $this->getOption("passwd");
745
        if ($sHash == $pwd["OptValue"]) {
746
            $result["ERR"] = 0;
747
            $result["Location"] = "manager.php";
748
            setcookie($this->cookie, $sHash);
749
        } else {
750
            $result["ERR"] = 1;
751
            $result["ERRINFO"] = "Password not valid";
368 alex-w 752
            $result["Location"] = "manager.php?error=1";
359 alex-w 753
        }
754
 
755
        return $result;
358 alex-w 756
    }
357 alex-w 757
 
463 alex-w 758
    /**
759
     * Проверка пароля (из cookies)
760
     *
761
     * @author Alexander Wolf
762
     * @category Core
763
     *
764
     * @param string $hash
765
     * @return array
766
     */
368 alex-w 767
    public function checkCookieSign($hash) {
359 alex-w 768
        $result = array();
769
 
770
        $pwd = $this->getOption("passwd");
771
        if ($hash == $pwd["OptValue"]) {
772
            $result["ERR"] = 0;
773
        } else {
774
            $result["ERR"] = 1;
775
            $result["ERRINFO"] = "Hash not valid";
368 alex-w 776
            $result["Location"] = "manager.php";
359 alex-w 777
        }
778
 
779
        return $result;
780
    }
781
 
463 alex-w 782
    /**
783
     * Форма ввода пароля
784
     *
785
     * @author Alexander Wolf
786
     * @category Core
787
     *
788
     * @return string
789
     */
368 alex-w 790
    public function showSigninForm() {
425 alex-w 791
        $show  = "<div id='regform'>";
792
        $show .= "<form action='process.php' method='post'>\n";
368 alex-w 793
        $show .= "<fieldset><legend>Пароль</legend>\n";
794
        $show .= "<input type='hidden' name='mode' value='authorize'>\n";
427 alex-w 795
        $show .= "<input type='password' name='word' value=''>\n";
368 alex-w 796
        $show .= "<input type='submit' value=' Войти '>\n";
425 alex-w 797
        $show .= "</fieldset>\n</form></div>\n";
368 alex-w 798
 
799
        return $show;
800
    }
801
 
463 alex-w 802
    /**
803
     * Обновление пароля
804
     *
805
     * @author Alexander Wolf
806
     * @category Core
807
     *
808
     * @param string $word1
809
     * @param string $word2
810
     * @return array
811
     */
368 alex-w 812
    public function updatePassword($word1, $word2) {
359 alex-w 813
        $result = array();
814
 
815
        if ($word1 == $word2) {
816
            $sWord = $this->secure->encryptStr($word1);
817
            $r = $this->setOption("passwd", $sWord);
818
            $result = $r;
819
        } else {
820
            $result["ERR"] = 1;
821
            $result["ERRINFO"] = "Passwords is mismatch";
822
        }
823
 
824
        return $result;
825
    }
826
 
504 alex-w 827
    /**
509 alex-w 828
     * Отображение формы создания и редактирования версии apt-дистрибутива
504 alex-w 829
     *
830
     * @author Alexander Wolf
831
     * @category Core
832
     *
833
     * @param string $name
834
     * @param string $actor
835
     * @param integer $versionID
836
     * @return string
837
     */
511 alex-w 838
    public function showDistVersionsForm($versionID = 0, $info = '') {
509 alex-w 839
        $sVersionID = $this->secure->checkInt($versionID);
511 alex-w 840
        $sInfo = $this->secure->checkStr($info, 1);
841
        if ($sInfo == "") {
842
            $sInfo = "Версия дистрибутива";
843
        }
509 alex-w 844
        if ($sVersionID != 0) {
845
            // Режим редактирования
497 alex-w 846
            $query = "SELECT * FROM ".$this->prefix."version v JOIN ".$this->prefix."distribution d ON v.dist_id=d.dist_id WHERE v.version_id='".$versionID."'";
847
            $rq =& $this->db->query($query);
848
            $rq->fetchInto($element);
509 alex-w 849
        }
850
 
511 alex-w 851
        $show  = "<fieldset><legend>".$sInfo."</legend>\n";
510 alex-w 852
        if ($sVersionID != 0) {
853
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> <input type='text' name='distname' value='".$this->secure->checkStr($element["distname"],1)."' readonly='readonly'></div>\n";
854
        } else {
855
            $show .= "<div class='inputbox'><label for='distname'>Дистрибутив:</label> ".$this->showDistributionList("distname", "", "", "innerhtml")."</div>\n";
856
        }
509 alex-w 857
        $show .= "<div class='inputbox'><label for='vname'>Название версии:</label> <input type='text' name='vname' value='".$this->secure->checkStr($element["vname"],1)."'></div>\n";
858
        $show .= "<div class='inputbox'><label for='version'>Номер версии:</label> <input type='text' name='version' value='".$this->secure->checkStr($element["version"],1)."'></div>\n";
859
        $show .= "<div class='inputbox'><label for='vcodename'>Кодовое имя версии:</label> <input type='text' name='vcodename' value='".$this->secure->checkStr($element["vcodename"],1)."'></div>\n";
860
        $show .= "<div class='inputbox'><input type='submit' value=' Отправить данные '></div></fieldset>\n";
495 alex-w 861
 
504 alex-w 862
        return $show;
509 alex-w 863
    }    
504 alex-w 864
 
520 alex-w 865
    /**
866
     * Парсер схемы адреса репозитория
867
     * FIXME Возможно не потребуется
868
     *
869
     * @author Alexander Wolf
870
     * @category Core
871
     *
872
     * @param string $repstring
873
     * @return integer
874
     */
875
    public function repositoryParser($repstring) {
876
        $tokens = array();
877
        $sections = array();
878
        $tokens = split(" ",$repstring);
879
 
880
        if ($tokens[0] == "deb") {
881
            // debian/ubuntu репозиторий "type proto://host/folder distr sections"
882
            $url = parse_url($tokens[1]);
883
            $distr  = $tokens[2];
884
 
885
            for($i=3;$i<count($tokens);$i++) {
886
                $sections[] = $tokens[$i];
887
            }
888
        } else {
889
            // altlinux репозиторий "type [sign] proto://host/folder base repname"
890
            if (stripos($tokens[1],"]")!=0) {
891
                $sign = $tokens[1];
892
                $url = parse_url($tokens[2]);
893
                $base = $tokens[3];
894
                $repname = $tokens[4];
895
            } else {
896
                $url = parse_url($tokens[1]);
897
                $base = $tokens[2];
898
                $repname = $tokens[3];
899
            }
900
        }
901
 
902
        $proto      = $url["scheme"]."://";
903
        $addr       = $url["host"];
904
        if ($url["port"]!="") {
905
            $addr .= ":".$url["port"];
906
        }
907
        $path       = $url["path"];
908
 
909
        return 0;
910
    }
911
 
535 alex-w 912
    public function uploadPicture($path, $dist, $datafile) {
913
        $folder   = $path.$dist."-orig.png";
914
        $folderN  = $path.$dist.".png";
915
        $folderEM = $path.$dist."-em.png";
916
 
917
        $distlogo = 0;
918
        if (move_uploaded_file($datafile["distlogo"]["tmp_name"],$folder)) {
919
            chmod($folder, 0644);
920
            list($width, $height) = GetImageSize($folder);
921
            $percent = 32/$height;
922
            $newwidth = $width * $percent;
923
            $newheight = $height * $percent;
924
 
925
            $output = ImageCreateTrueColor($newwidth, $newheight);
926
            $source = ImageCreateFromPNG($folder);
927
 
928
            ImageCopyResampled($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
929
            ImagePNG($output, $folderEM);
930
 
931
            $percent = 15/$height;
932
            $newwidth = $width * $percent;
933
            $newheight = $height * $percent;
934
 
935
            $output = ImageCreateTrueColor($newwidth, $newheight);
936
 
937
            ImageCopyResized($output, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
938
            ImagePNG($output, $folderN);
939
 
940
            unlink($folder);
941
            $distlogo = 1;
942
        }
943
        return $distlogo;
944
    }
304 alex-w 945
}
946
 
356 alex-w 947
?>