function select_month($arr) {
while ($row = mysql_fetch_array($arr)) {
$id = $row['ID'];
}
return $id;
}
function getMonth($t) {
switch ($t){
case 1: $m='Январь'; break;
case 2: $m='Февраль'; break;
case 3: $m='Март'; break;
case 4: $m='Апрель'; break;
case 5: $m='Май'; break;
case 6: $m='Июнь'; break;
case 7: $m='Июль'; break;
case 8: $m='Август'; break;
case 9: $m='Сентябрь'; break;
case 10: $m='Октябрь'; break;
case 11: $m='Ноябрь'; break;
case 12: $m='Декабрь'; break;
}
return $m;
}
$id_year = NULL;
$cur_year = date("Y");
$id_y = mysql_query("sel ect * fr om b_iblock_section where code = '".$cur_year."'");
if (mysql_num_rows($id_y) > 0) {
$id_year = select_month($id_y);
} else {
mysql_query("
INS ERT INTO b_iblock_section (IBLOCK_ID,ACTIVE,GLOBAL_ACTIVE,SORT,NAME,CODE,DEPTH_LEVEL)
VALUES ('15','Y','Y','500','".$cur_year."','".$cur_year."',1);
");
$id_y = mysql_query("sel ect * fr om b_iblock_section where code = '".$cur_year."'");
$id_year = select_month($id_y);
}
$id_m = mysql_query("sel ect * fr om b_iblock_section where IBLOCK_SECTION_ID = '".$id_year."'");
if (mysql_num_rows($id_m) > 0) {
$id_month = select_month($id_m);
} else {
mysql_query("
INS ERT INTO b_iblock_section (IBLOCK_ID,ACTIVE,GLOBAL_ACTIVE,SORT,NAME,CODE,DEPTH_LEVEL,IBLOCK_SECTION_ID)
VALUES ('15','Y','Y','500','".getMonth(date("m"))."','".date("m")."',2,".$id_year.");
");
$id_m = mysql_query("select * fr om b_iblock_section where IBLOCK_SECTION_ID = '".$id_year."'");
$id_month = sele ct_month($id_m);
}
mysql_query("ins ert in to b_iblock_section_element (IBLOCK_SECTION_ID,IBLOCK_ELEMENT_ID) val ues ('{$id_month}','{$id_element}')");
mysql_query("upd ate b_iblock_element se t IBLOCK_SECTION_ID = '{$id_month}' wh ere id = '{$id_element}'"); |