Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
2 | leon | 1 | <?PHP |
2 | //Проверяем авторизацию |
||
3 | session_start(); |
||
4 | if ($_SESSION['$user_privileges'] < 16) |
||
5 | header("Location: index.php"); |
||
6 | include "head.php"; |
||
7 | include "config.php"; |
||
8 | $template_id = $_GET['template_id']; |
||
9 | $db = mysql_connect("localhost", "linwin"); |
||
10 | mysql_select_db("linwin", $db); |
||
11 | mysql_query("SET NAMES 'utf8';", $db); |
||
12 | |||
13 | //Загружем данные шаблона |
||
14 | $sql = "SELECT name FROM templates WHERE id = ". $template_id; |
||
15 | $query=mysql_query($sql, $db); |
||
16 | $template_name = mysql_result($query,0,0); |
||
17 | |||
18 | //Загружаем таблицу программ входящих в шаблон |
||
19 | $sql = "SELECT pid FROM prog_in_temp WHERE tid = ". $template_id; |
||
20 | $query=mysql_query($sql, $db); |
||
21 | $num_record = mysql_num_rows($query); |
||
22 | for($i = 0; $i < $num_record; $i++) |
||
23 | $mas_prog_in_temp_id[$i] = mysql_result($query,$i,0); |
||
24 | $sql_part = "('". $mas_prog_in_temp_id[0]; |
||
25 | for ($i = 1; $i < count($mas_prog_in_temp_id); $i++) |
||
26 | { |
||
27 | $sql_part = $sql_part. "','". $mas_prog_in_temp_id[$i]; |
||
28 | } |
||
29 | $sql_part = $sql_part. "')"; |
||
30 | $sql = "SELECT id, name, description FROM program WHERE id in ". $sql_part. " ORDER BY name"; |
||
31 | $query = mysql_query($sql, $db); |
||
32 | $mas_program_id = array(); |
||
33 | $mas_program_name = array(); |
||
34 | $mas_program_description = array(); |
||
35 | $num_record = mysql_num_rows($query); |
||
36 | for ($i = 0; $i < $num_record; $i++) |
||
37 | { |
||
38 | $mas_program_id[] = mysql_result($query, $i, 0); |
||
39 | $mas_program_name[] = mysql_result($query, $i, 1); |
||
40 | $mas_program_description[] = mysql_result($query, $i, 2); |
||
41 | } |
||
42 | |||
43 | //Загружем таблицу урлов для программ данного шаблона |
||
44 | $sql = "SELECT id, description,url, local_mirror FROM url WHERE pid in ". $sql_part; |
||
45 | $query = mysql_query($sql, $db); |
||
46 | $mas_url_id = array(); |
||
47 | $mas_url_description = array(); |
||
48 | $mas_url_url = array(); |
||
49 | $mas_local_mirror = array(); |
||
50 | $num_record = mysql_num_rows($query); |
||
51 | for ($i = 0; $i < $num_record; $i++) |
||
52 | { |
||
53 | $mas_url_id[] = mysql_result($query, $i, 0); |
||
54 | $mas_url_description[] = mysql_result($query, $i, 1); |
||
55 | $mas_url_url[] = mysql_result($query, $i, 2); |
||
56 | $mas_url_local_mirror[] = mysql_result($query, $i, 3); |
||
57 | } |
||
58 | |||
59 | //Очищаем каталог временных файлов |
||
60 | $exec = "rm -rf $temp_dir"."* && /usr/bin/php-cgi -q $base_dir_linwin". "create_index.php template_id=". "$template_id > $temp_dir". "index.html"; |
||
61 | if ($debug == "1") |
||
62 | print "<br/>Строка запуска rm:<br/>$exec<br/>"; |
||
63 | $program_out = shell_exec($exec); |
||
64 | if ($debug == "1") |
||
65 | print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>"; |
||
66 | |||
67 | //Выкачиваем все урлы |
||
68 | for ($i = 0; $i < $num_record; $i++) |
||
69 | { |
||
70 | if ($mas_url_local_mirror[$i] == "1") |
||
71 | { |
||
72 | $exec = "cd $temp_dir && /usr/bin/wget -nH -x -N". " $base_url_software$mas_url_url[$i]"; |
||
73 | if ($debug == "1") |
||
74 | print "<br/>Строка запуска wget:<br/>$exec<br/>"; |
||
75 | $program_out = shell_exec($exec); |
||
76 | if ($debug == "1") |
||
77 | print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>"; |
||
78 | print "Выкачали($i из $num_record(не верно!!!)): ". "$mas_url_url[$i]". "<br/>"; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | //Подготавливаем html |
||
83 | $exec = "/usr/bin/php-cgi -q $base_dir_linwin". "create_index.php template_id=". "$template_id > $temp_dir". "index.html"; |
||
84 | if ($debug == "1") |
||
85 | print "<br/>Строка запуска php-cgi:<br/>$exec<br/>"; |
||
86 | $program_out = shell_exec($exec); |
||
87 | if ($debug == "1") |
||
88 | print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>"; |
||
89 | |||
90 | //Создаем iso образ |
||
91 | $exec = "/usr/bin/genisoimage -J -o $template_dir". "$template_name". ".iso $temp_dir"; |
||
92 | if ($debug == "1") |
||
93 | print "<br/>Строка запуска genisoimage:<br/>$exec<br/>"; |
||
94 | $program_out = shell_exec($exec); |
||
95 | if ($debug == "1") |
||
96 | print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>"; |
||
97 | |||
98 | //Создаем zip архив |
||
99 | $exec = "cd $temp_dir && /usr/bin/zip -9 -r $template_dir". "$template_name". " *"; |
||
100 | $program_out = shell_exec($exec); |
||
101 | |||
102 | include "foot.php"; |
||
103 | ?> |