function arraysql($sql, $defname) { $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($lname)) { $lname[] = "izberi lokacijo..."; $lvalue[] = ""; } $lname[] .= $res["id"] . "; " . $res["name_location"]; $lvalue[] .= $res["id"]; } $location_dropdown = html_drop_down_arrays("location_drop", $lname, $lvalue, $location_drop); }
$name_dropdown = html_drop_down_arrays("entry.1.single",$names,$values,$name_drop); */ $sql = "SELECT * FROM applic"; $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($aname)) { $aname[] = "izberi program..."; $avalue[] = ""; } $aname[] .= $res["name"]; $avalue[] .= $res["name"]; } $appl_dropdown = html_drop_down_arrays("entry.4.single", $aname, $avalue, $appl_drop); $sql = "SELECT * FROM work WHERE {$ROLE_USER}>=`group` order by applic"; $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($wname)) { $wname[] = "izberi delo..."; $wvalue[] = ""; } $wname[] .= $res["applic"] . "; " . $res["name"]; $wvalue[] .= $res["applic"] . "; " . $res["name"]; } $work_dropdown = html_drop_down_arrays("entry.5.single", $wname, $wvalue, $work_drop); $tem = str_replace('##USER##', $identity, $tem); //$tem = str_replace('##NAMES##',$name_dropdown,$tem); //$tem = str_replace('##PROGRAM##',$appl_dropdown,$tem); $tem = str_replace('##WORK##', $work_dropdown, $tem); $tem = template_clean_up_tags($tem, "##"); echo $tem;
// $sql = "SELECT * FROM jobtype where role between 30 and 79 order by name ASC"; // } //else { // $sql = "SELECT * FROM jobtype where role > 79 order by name ASC"; //} $sql = "SELECT * FROM jobtype where role between 10 and {$role_id} order by name ASC"; $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($names_job)) { $names_job[] = "izberi tip izhoda..."; $values_job[] = ""; } $names_job[] .= $res["name"]; $values_job[] .= $res["job_id"]; } $job_dropdown = html_drop_down_arrays("job_drop", $names_job, $values_job, $job_drop); $name = $_REQUEST['name']; if ($_REQUEST['add'] == " Dodaj ") { /*$start_time = mktime ($HOUR_START, $MIN_START, 0, date("n",time()) , date("j",time()) , $year= date("Y",time())); $stop_time = mktime ($HOUR_STOP, $MIN_STOP, 0, date("n",time()) , date("j",time()) , $year= date("Y",time()));*/ $start_time = mktime($HOUR_START, $MIN_START, 0, $MONTH_START, $DAY_START, $year = date("Y", time())); $stop_time = mktime($HOUR_STOP, $MIN_STOP, 0, $MONTH_START, $DAY_START, $year = date("Y", time())); //preveri ce je v month reportu ze izpisan in ce je ga ne dovoli vpisat $sql_log = "SELECT date \r\n\tFROM `log_report` \r\n\tWHERE date='" . "0" . $MONTH_START . $year . $role_id . "' order by log_id DESC limit 1"; $get_log = $db->fetchAll($sql_log); if ($get_log[0]["date"]) { //header("location:log_error.php"); $message .= "Vnasati v mesec katerega porocilo je bilo oddano ni mogoce!"; //exit; } else { if ($name_drop and $job_drop and $MONTH_START and $DAY_START and $start_time and $stop_time) {
for ($x = 2009; $x <= $Y; $x++) { $names[] .= $x; } $values = $names; $year_dropdown = html_drop_down_arrays("year", $names, $values, date("Y", time())); /////////////////// /* get names */ $names = ""; $values = ""; $sql = "SELECT * FROM persons WHERE (if({$role_id}>70,if({$role_id}>80,unit>=0,unit={$role_id}),(id_role<12 and (select unit from persons where id_person={$person_id})=unit ))) order by letter ASC"; $result = $db->fetchAll($sql); foreach ($result as $res) { $names[] .= $res["last"] . " " . $res["first"]; $values[] .= $res["id_person"]; } $name_dropdown = html_drop_down_arrays("name_drop", $names, $values, $name_drop); ////////////////////// if ($role_id >= $ROLE_LIST) { $sql = "SELECT `id`,day(from_unixtime(start))datum,`timestamp`,\n applic.name program,work.name delo, `testing`,`persons`.`first` ime_varov,\n `persons`.`last` priim_varov, time(from_unixtime(`start`)) start, time(from_unixtime(`end`)) end ,\n sec_to_time((`end`) -(`start`)) delal,sec_to_time((`end`) -(`start`)-pause) adelal,\n sec_to_time(`work_log`.`pause`) odmori,`work_log`.`assessment` ocena, `work`.`name`, `comm`,`work`.`payment`, unit, id_role\n FROM\n (applic JOIN `work` ON applic.`applic_id`=work.`applic_id`)\n RIGHT OUTER JOIN\n (persons right outer join work_log on persons.id_person=work_log.person_id) ON work_log.work_id=work.work_id\n WHERE id{$id}\n ORDER BY applic.name,date(from_unixtime(start))"; ///unit ne pozabit $result = $db->fetchAll($sql); foreach ($result as $res) { $table = $row; $table = str_replace("##ID##", $res["id"], $table); $table = str_replace("##DATUM##", $res["datum"], $table); //$table = str_replace("##NAME##",$res["ime_varov"]." ".$res["priim_varov"],$table); $table = str_replace("##PROGRAM##", $res["program"], $table); $table = str_replace("##DELO##", $res["delo"], $table); $table = str_replace("##DELAL##", $res["delal"], $table); $table = str_replace("##ODMOR##", $res["odmori"], $table); $table = str_replace("##ADELAL##", $res["adelal"], $table);
$lvalue[] .= $res["id"]; } $location_dropdown = html_drop_down_arrays("location_drop", $lname, $lvalue, $location_drop); ////////////////////// //dropdown za izbiro aktivnosti uporabnika $sql = "SELECT * FROM `work` WHERE {$ROLE_USER}>=`group` ORDER BY `applic`"; $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($wname)) { $wname[] = "izberi aktivnost..."; $wvalue[] = ""; } $wname[] .= $res["applic"] . " --> " . $res["name"]; $wvalue[] .= $res["work_id"]; } $work_dropdown = html_drop_down_arrays("work_drop", $wname, $wvalue, $work_drop); //////////// //get user id $sql = "SELECT id_person FROM persons where username='******'"; $user_id = $db->fetchOne($sql); $name = $_REQUEST['name']; if ($_REQUEST['add'] == " Shrani ") { //Če je administrator se štejejo tudi dnevi in se lahko izbere tudi ocenjevalec if ($role_id >= 80) { $start_time = mktime($hour_start_time_drop, $min_start_time_drop, 0, $month_drop, $day_drop, $year_drop); $stop_time = mktime($hour_stop_time_drop, $min_stop_time_drop, 0, $month_drop, $day_drop, $year_drop); $pause_time = $pause_hour_time_drop * 3600 + $pause_min_time_drop * 60; } else { $start_time = mktime($hour_start_time_drop, $min_start_time_drop, 0, date("n", time()), date("j", time()), $year = date("Y", time())); $stop_time = mktime($hour_stop_time_drop, $min_stop_time_drop, 0, date("n", time()), date("j", time()), $year = date("Y", time())); $pause_time = $pause_hour_time_drop * 3600 + $pause_min_time_drop * 60;
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $Y = date("Y", time()); for ($x = 2009; $x <= $Y; $x++) { $ynames[] .= $x; } $yvalues = $ynames; $year_dropdown = html_drop_down_arrays("year", $ynames, $yvalues, date("Y", time())); $tem = str_replace("##YDROP##", $year_dropdown, $tem);
//trenutni mesec $mesec_start = date("m", time()); $year=date("Y", time()); $shour = range(0, 23); $shour_dropdown = html_drop_down_arrays("shour_drop", $shour, $shour, "7"); $smin = range(0, 59); $smin_dropdown = html_drop_down_arrays("smin_drop", $smin, $smin, $smin_drop); $ehour = range(0, 23); $ehour_dropdown = html_drop_down_arrays("ehour_drop", $ehour, $ehour, "15"); $emin = range(0, 59); $emin_dropdown = html_drop_down_arrays("emin_drop", $emin, $emin, $emin_drop); $name = $_REQUEST['name']; if ($_REQUEST['add'] == " Shrani ") { $start_time = mktime($shour_drop, $smin_drop, 0, date("n", time()), date("j", time()), $year = date("Y", time())); $stop_time = mktime($ehour_drop, $emin_drop, 0, date("n", time()), date("j", time()), $year = date("Y", time())); $sql_log = "SELECT date FROM `log_report` WHERE date=concat('$mesec_start','$year',$unit) order by log_id DESC limit 1"; // concat('0','8','2010','77')
$result = $db->fetchAll($sql); foreach ($result as $res) { $locnames[] .= $res["name_location"] . " " . $res["first"]; $locvalues[] .= $res["id"]; } /////////// foreach ($dresult as $dres) { $count++; $table = $row; $table = str_replace("##DID##", $dres["id"], $table); $table = str_replace("##DEAN##", $dres["inventory_ean"], $table); $table = str_replace("##DNAME##", $dres["name"], $table); // $table = str_replace("##DCREATED##", $dres["created"], $table); $name_dropdown = html_drop_down_arrays("name_drop[]", $names, $values, $dres["person_id"], "form_textbox"); $unitname_dropdown = html_drop_down_arrays("unitname_drop[]", $unitnames, $unitvalues, $dres["unit"], "form_textbox"); $locname_dropdown = html_drop_down_arrays("locname_drop[]", $locnames, $locvalues, $dres["place"], "form_textbox"); $table = str_replace("##NAMEDROP##", $name_dropdown, $table); $table = str_replace("##DUNIT##", $unitname_dropdown, $table); $table = str_replace("##DPLACE##", $locname_dropdown, $table); $table = str_replace("##DPERSONID##", $dres["person_id"], $table); $table = str_replace("##DDESCRIPTION##", $dres["descr"], $table); $dwhole_table .= $table; } $tem = str_replace("##DLOGS##", $dwhole_table, $tem); $tem = str_replace("##DMESSAGE##", $message, $tem); if ($_REQUEST['edit'] == "spremeni") { //dejansko vnesemo for ($i = 0; $i < $count; $i++) { // $db->query('UPDATE LogInventory SET unit=' . $dunit[$i] . ', place=' . $dplace[$i] . ', person_id=' . $dpersonid[$i] . ', description="' . $ddescription[$i] . '" where id = (' . $did[$i] . ')' . ''); $db->query('UPDATE LogInventory SET unit=' . $unitname_drop[$i] . ', place=' . $locname_drop[$i] . ', person_id=' . $name_drop[$i] . ', description="' . $ddescription[$i] . '" where id = (' . $did[$i] . ')' . ''); }
$names[] = "Moski"; $names[] = "Zenska"; $values[] = "M"; $values[] = "F"; $sex_dd = html_drop_down_arrays('sex',$names,$values,$sex); //get events $sql="select * from events"; $db->query($sql); while ($db->next_record()) { $e_names[] = $db->f("name"); $e_values[] = $db->f("event_id"); } $event_dd = html_drop_down_arrays('event',$e_names,$e_values,$event); //replace template variables// $tem = str_replace("##SEX##",$sex_dd,$tem); $tem = str_replace("##EVENT##",$event_dd,$tem); if (!$sucsess) { $tem = str_replace("##CLUB##",$club,$tem); $tem = str_replace("##FULL_NAME##",$full_name,$tem); $tem = str_replace("##CITY##",$city,$tem); $tem = str_replace("##NUMBER##",$number,$tem); $tem = str_replace("##CITY##",$city,$tem); }
ORDER BY users.number ASC"; $db->query($sql); while ($db->next_record()) { $u_names[] = $db->f("number")." - ".$db->f("full_name"); $u_values[] = $db->f("id_user"); } $u_drop = html_drop_down_arrays_multiple('users',$u_names,$u_values,$selected,10); //tekma drop down// $sql = "Select * from tekma"; $db->query($sql); while ($db->next_record()) { $t_names[] = $db->f("name"); $t_values[] = $db->f("tekma_id"); } $t_drop = html_drop_down_arrays('tekma',$t_names,$t_values,$selected); //replace template variables// $tem = str_replace("##TITLE##",$title,$tem); $tem = str_replace("##USER_DROP##",$u_drop,$tem); $tem = str_replace("##TEKMA_DROP##",$t_drop,$tem); $tem = str_replace("##EVENT_ID##",$event_id,$tem); $tem = str_replace("##MESSAGE##",$message,$tem); ///clean up// $tem = template_clean_up_tags($tem,"##"); //output of the template// echo $tem;
//$nsql = "SELECT * FROM `work_log` WHERE `assessor_id`=3 and end=0 and start<>0"; $nsql = "SELECT work_log.id, persons.first, persons.last, time_format(from_unixtime(work_log.start),'%H:%i') as begin, work.name as wname, applic.name as aname, work_log.comm\nFROM persons right join\n (`work_log` left join\n (work\n LEFT JOIN applic on applic.applic_id=work.applic_id) on work_log.work_id=work.work_id)ON persons.id_person=work_log.person_id\n WHERE start<>0 and end=0 and assessor_id=3"; $nresult = $db->fetchAll($nsql); $count = 0; foreach ($nresult as $nres) { $count++; $table = $row; $table = str_replace("##EDITFORMNAME##", "editform" . $count, $table); $table = str_replace("##NID##", $nres["id"], $table); $qpause_hour_time_dropdown = html_drop_down_arrays("pause_hour_time_drop", $qpause_hour_time, $qpause_hour_time, $pause_hour_time_drop); //date("H",time())); $qpause_min_time_dropdown = html_drop_down_arrays("pause_min_time_drop", $qpause_min_time, $qpause_min_time, $pause_min_time_drop); //date("H",time())); $table = str_replace("##PAUSEHOUR##", $qpause_hour_time_dropdown, $table); $table = str_replace("##PAUSEMINUTES##", $qpause_min_time_dropdown, $table); $qrating_dropdown = html_drop_down_arrays("rating_drop", $qrating, $qrating, "3"); //date("H",time())); $table = str_replace("##RATING##", $qrating_dropdown, $table); $nactivitystop_textbox = html_input_text("name_drop", substr($nres[aname], 0, 8) . "... " . $nres[wname], 30, "textbox_red"); $nname_textbox = html_input_text("name_drop", $nres['first'] . " " . $nres['last'], 25, "textbox_red"); $nstart_textbox = html_input_text("name_drop", $nres["begin"], 2, "textbox_red"); $table = str_replace("##NSTART##", $nstart_textbox, $table); $table = str_replace("##ACTIVITYSTOP##", $nactivitystop_textbox, $table); $table = str_replace("##NAMEDROPSTOP##", $nname_textbox, $table); //$name_dropdown = html_drop_down_arrays("name_drop", $names, $values, $nres["person_id"], "dropdown_red"); //$activity_stop_dropdown = html_drop_down_arrays("activity_drop", $ActivityName, $ActivityValue, $nres["work_id"], "dropdown_red"); //$table = str_replace("##NAMEDROPSTOP##", $name_dropdown, $table); //$table = str_replace("##ACTIVITYSTOP##", $activity_stop_dropdown, $table); $table = str_replace("##DDESCRIPTION##", $nres["comm"], $table); $nwhole_table .= $table; }
} //get user number with user_id $sql="SELECT * FROM users RIGHT JOIN timming ON timming.user_id = users.id_user WHERE timming.stop =0"; $db->query($sql); while ($db->next_record()) { $e_names[] = $db->f("number"); $e_values[] = $db->f("id_user"); } $id_userdd = html_drop_down_arrays('user_id',$e_names,$e_values,"SELECTIRAN"); //document.form1.field1.select(); //replace template variables// if (!$success) { $tem = str_replace("##NUMBER##",$number,$tem); } $tem = str_replace("##MESSAGE##",$message,$tem);
//get last used persons_id $sql = "SELECT persons_id\n FROM aim\n WHERE created_by='{$person_id}'\n ORDER BY id DESC\n LIMIT 0, 1"; $last_add_user_id = $db->fetchOne($sql); //person drop down $sql = "SELECT * FROM `persons` WHERE `id_role`<'11 and unit={$unit}'"; $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($PersonName)) { $PersonName[] = "izberi osebo..."; $PersonValue[] = ""; } $PersonName[] .= $res["first"] . " " . $res["last"]; $PersonValue[] .= $res["id_person"]; } /////////// $person_dropdown = html_drop_down_arrays("person_drop", $PersonName, $PersonValue, $last_add_user_id); //activity drop down $sql = "SELECT * FROM `work` WHERE `group`<'11' order by applic"; $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($ActivityName)) { $ActivityName[] = "izberi aktivnost..."; $ActivityValue[] = ""; } $ActivityName[] .= $res["applic"] . " --> " . $res["name"]; $ActivityValue[] .= $res["work_id"]; } /////////// $activity_dropdown = html_drop_down_arrays_multiple("activity_drop", $ActivityName, $ActivityValue, $ActivityName, 10); $aim_name_textbox = html_input_text("aim_name_text", $aim_name_textbox, 25, "default"); $aim_duration_textbox = html_input_text("aim_duration_text", $aim_duration_textbox, 5, '$aim_duration_text');
} else { $message = "Manjkajoca polja!"; } } //get events $sql="SELECT autoNum FROM `users` right join start_number on users.number=start_number.autoNum where users.number is null"; $db->query($sql); while ($db->next_record()) { $e_names[] = $db->f("autoNum"); $e_values[] = $db->f("autoNum"); } $numdd = html_drop_down_arrays('startNum',$e_names,$e_values,$startNum); //replace template variables// if (!$success) { $tem = str_replace("##NUMBER##",$number,$tem); } $tem = str_replace("##MESSAGE##",$message,$tem);
} $aname[] .= $res["applic_id"] . "." . $res["subcat_id"] . " --> " . $res["name"]; $avalue[] .= $res["work_id"]; } $work_dropdown = html_drop_down_arrays("work_drop", $aname, $avalue, $work_drop); $sql = "SELECT * FROM locations where `type`=1 order by `name_location`"; $result = $db->fetchAll($sql); foreach ($result as $res) { if (!is_array($lname)) { $lname[] = "izberi lokacijo..."; $lvalue[] = ""; } $lname[] .= $res["name_location"]; $lvalue[] .= $res["id"]; } $location_dropdown = html_drop_down_arrays("location_drop", $lname, $lvalue, $location_drop); //get user id $sql = "SELECT id_person FROM persons where username='******'"; $user_id = $db->fetchOne($sql); $name = $_REQUEST['name']; if ($_REQUEST['add'] == " Shrani ") { $start_time = mktime($hour_start_time_drop, $min_start_time_drop, 0, date("n", time()), date("j", time()), $year = date("Y", time())); $stop_time = mktime($hour_stop_time_drop, $min_stop_time_drop, 0, date("n", time()), date("j", time()), $year = date("Y", time())); //Preveri, če so vsa polja izpolnjena in če se vpis slučajno ne prikeriva s kaksnim if ($user_id and $location_drop and $start_time and $stop_time and $start_time < $stop_time) { //$sql = "SELECT timestamp FROM work_log where person_id = '$user_id' and work_id=$work_drop and location_id =$location_drop and start='$start_time' and end='$stop_time'"; $sql = "SELECT timestamp,id FROM work_log where (person_id = '{$user_id}' and (end >'{$start_time}' AND start<'{$stop_time}')) or assessor_id= '{$user_id}' and (end >'{$start_time}' AND start<'{$stop_time}')"; $result = $db->fetchAll($sql); $success = true; $check_id = $result[0]["id"]; if (!$result) {
<?php require_once "inc/config.php"; $tem = template_open("add_plan.tpl"); $tem = template_add_head_foot($tem); $work_values = array(); $work_names = array(); //get out different types of work $sql = "SELECT id,naziv FROM delo"; $result = $db->fetchAll($sql); foreach ($result as $row) { $work_values[] = $row['id']; $work_names[] = $row['naziv']; } //create a dropdown $work_drop = html_drop_down_arrays("work_id", $work_names, $work_values, ''); //get user id $sql = "SELECT id FROM users where username='******'"; $user_id = $db->fetchOne($sql); ///form submit $title = $_REQUEST['title']; $desc = $_REQUEST['desctiption']; $price = $_REQUEST['price']; if ($_REQUEST['form_submit'] == "true") { if ($title and $desc and $price) { //pogledamo kaj imamo in ce je ze tak notr slucajn.. //dejansko vnesemo $data = array('naziv' => $title, 'id_user' => $user_id, 'id_delo' => $work_id); $db->insert('main', $data); $message .= "Delo je dodano.."; } else {
check_role($ROLE_ADMIN); $tem = template_open("add_address.tpl"); $tem = template_add_head_foot($tem, head, foot); $username = ereg_replace("[^[A-z]]", "", $_REQUEST['username']); $password = ereg_replace("[^[A-z]]", "", $_REQUEST['password']); $first = ereg_replace("[^[:alnum:] ]", "", $_REQUEST['first']); $last = ereg_replace("[^[:alnum:] ]", "", $_REQUEST['last']); echo "do sem"; $sql = "SELECT * FROM roles"; //TitleGroup"; $result = $db->fetchAll($sql); foreach ($result as $res) { $names[] .= $res["name"]; $values[] .= $res["id_role"]; } $role_dropdown = html_drop_down_arrays("role_drop", $names, $values, ""); if ($_REQUEST['add'] == "Dodaj") { //echo $username."-".$password."-".$first."-".$last."-".$role_drop; if ($username and $password and $first and $last) { //pogledamo kaj imamo in ce je ze tak notr slucajn... $sql = "SELECT first FROM persons where first='{$first}' and last='{$last}'"; $result = $db->fetchOne($sql); if ($result) { $message .= "Uporabnik ze obstaja"; } else { // dejansko vnesemo $data = array('username' => $username, 'passwd' => $password, 'first' => $first, 'last' => $last, 'id_role' => $role_drop); $db->insert('persons', $data); $message .= "Uporabnik dodan.."; } } else {
$time = time(); require_once "inc/config.php"; check_role($ROLE_LEADER); $TITLE = "Pregled vpisanih aktivnosti za"; $tem = template_open("view_paycheck.tpl"); $tem = template_add_head_foot($tem, head, foot); $tmp = template_get_repeat_text("##START_LOG##", "##STOP_LOG##", "##LOGS##", $tem); $row = $tmp[1]; $tem = $tmp[0]; $mon = (int) $_REQUEST["mon"]; $amount = (int) $_REQUEST["amount"]; for ($x = 1; $x < 13; $x++) { $names[] .= $x; } $values = $names; $month_dropdown = html_drop_down_arrays("mon", $names, $values, date("m", time())); //spremenljivki za mesec ine leto if ($mon < 1 or $mon > 12) { $mon = ''; } if (!$year) { $year = date("Y", time()); } if ($mon and $year and $amount) { //pogoj, da lahko vsi ki imajo nad 80 role_id vidijo vse in dopisujejo vse if ($role_id < $ROLE_ADMIN and $role_id > $ROLE_LEADER) { $sql = "SELECT MONTH( FROM_UNIXTIME( `end` ) ) mesec, `person_id` , `persons`.`first` ime_varov, `persons`.`last` priim_varov, \n\t\t(SUM( ( ( `end` - `start` - `pause` ) /3600 ) * `assessment` * IF( `persons`.`id_role` =10, '1', IF( `persons`.`id_role` =5, '0', IF( `persons`.`id_role` =8, '0.1', '0.33' ) ) )))\n\t\t * ( " . $amount . " / ( SELECT SUM( ( (`end` - `start` - `pause`) /3600 )\n\t\t * `assessment` * IF( `persons`.`id_role` =10, '1', IF( `persons`.`id_role` =5, '0', IF( `persons`.`id_role` =8, '0.1', '0.33' ) ) ) ) tocke\n\t\tFROM `work_log` , `work` , `persons` \n\t\tWHERE `work`.`work_id` = `work_log`.`work_id` \n\t\tAND `persons`.`id_person` = `work_log`.`person_id` \n\t\tAND `work`.`payment` =1\n\t\tAND (\n\t\tMONTH( FROM_UNIXTIME( `start` ) ) ={$mon}\n\t\tAND YEAR( FROM_UNIXTIME( `start` ) ) ={$year} and `persons`.`unit`={$role_id})\n\t\t)\n\t\t)eur\n\t\tFROM `work_log` , `work` , `persons` \n\t\tWHERE `work`.`work_id` = `work_log`.`work_id` \n\t\tAND `persons`.`id_person` = `work_log`.`person_id` \n\t\tAND `work`.`payment` =1\n\t\tAND (\n\t\tMONTH( FROM_UNIXTIME( `start` ) ) ={$mon}\n\t\tAND YEAR( FROM_UNIXTIME( `start` ) ) ={$year}\n\t\tand `persons`.`unit`={$role_id}\n\t\t)\n GROUP BY `person_id`\n order by `letter`"; } else { $sql = "SELECT MONTH( FROM_UNIXTIME( `end` ) ) mesec, `person_id` , `persons`.`first` ime_varov, `persons`.`last` priim_varov, \n\t\t(SUM( ( ( `end` - `start` - `pause` ) /3600 ) * `assessment` * IF( `persons`.`id_role` =10, '1', IF( `persons`.`id_role` =5, '0', IF( `persons`.`id_role` =8, '0.1', '0.33' ) ) )))\n\t\t * ( " . $amount . " / ( SELECT SUM( ( (`end` - `start` - `pause`) /3600 )\n\t\t * `assessment` * IF( `persons`.`id_role` =10, '1', IF( `persons`.`id_role` =5, '0', IF( `persons`.`id_role` =8, '0.1', '0.33' ) ) ) ) tocke\n\t\tFROM `work_log` , `work` , `persons` \n\t\tWHERE `work`.`work_id` = `work_log`.`work_id` \n\t\tAND `persons`.`id_person` = `work_log`.`person_id` \n\t\tAND `work`.`payment` =1\n\t\tAND (\n\t\tMONTH( FROM_UNIXTIME( `start` ) ) ={$mon}\n\t\tAND YEAR( FROM_UNIXTIME( `start` ) ) ={$year} )\n\t\t)\n\t\t)eur\n\t\tFROM `work_log` , `work` , `persons` \n\t\tWHERE `work`.`work_id` = `work_log`.`work_id` \n\t\tAND `persons`.`id_person` = `work_log`.`person_id` \n\t\tAND `work`.`payment` =1\n\t\tAND (\n\t\tMONTH( FROM_UNIXTIME( `start` ) ) ={$mon}\n\t\tAND YEAR( FROM_UNIXTIME( `start` ) ) ={$year}\n\t\t)\n\t\tGROUP BY `person_id`\n order by `letter`"; } // echo $sql;