/** * Assigns a group to 1-n group leaders by adding entries to the cross table * (counterpart to assign_ldr2grp) * * @param array $grp_id grp_id of the group to which the group leaders will be assigned * @param array $ldr_array contains one or more usr_ids of the leaders) * @global array $kga kimai-global-array * @return boolean true on success, false on failure * @author ob */ function assign_grp2ldrs($grp_id, $ldr_array) { global $kga, $conn; if (!$conn->TransactionBegin()) { $conn->Kill(); } $table = $kga['server_prefix'] . "ldr"; $filter['grp_ID'] = MySQL::SQLValue($grp_id, MySQL::SQLVALUE_NUMBER); $query = MySQL::BuildSQLDelete($table, $filter); $d_result = $conn->Query($query); if ($d_result == false) { $conn->TransactionRollback(); return false; } foreach ($ldr_array as $current_ldr) { $values['grp_ID'] = MySQL::SQLValue($grp_id, MySQL::SQLVALUE_NUMBER); $values['grp_leader'] = MySQL::SQLValue($current_ldr, MySQL::SQLVALUE_NUMBER); $query = MySQL::BuildSQLInsert($table, $values); $result = $conn->Query($query); if ($result == false) { $conn->TransactionRollback(); return false; } } update_leader_status(); if ($conn->TransactionEnd() == true) { return true; } else { return false; } }
/** * Assigns a group to 1-n group leaders by adding entries to the cross table * (counterpart to assign_ldr2grp) * * @param array $grp_id grp_id of the group to which the group leaders will be assigned * @param array $ldr_array contains one or more usr_ids of the leaders) * @global array $kga kimai-global-array * @return boolean true on success, false on failure * @author ob */ function assign_grp2ldrs($grp_id, $ldr_array) { global $kga, $pdo_conn; $p = $kga['server_prefix']; $pdo_conn->beginTransaction(); $d_query = $pdo_conn->prepare("DELETE FROM {$p}ldr WHERE grp_ID=?;"); $d_result = $d_query->execute(array($grp_id)); if ($d_result == false) { return false; } foreach ($ldr_array as $current_ldr) { $pdo_query = $pdo_conn->prepare("INSERT INTO {$p}ldr (grp_ID,grp_leader) VALUES (?,?);"); $result = $pdo_query->execute(array($grp_id, $current_ldr)); if ($result == false) { return false; } } update_leader_status(); if ($pdo_conn->commit() == true) { return true; } else { return false; } }