/** * Recursivly deletes old visit data stops after 10,000 have been removed * to save proccessing time. * * @param int $recno the recno of the referer to delete * @param string the table to delete from * @param array array of element IDs that calls to delete have been already been made for * * @global object $mydatabase mysql database object. * @global int Global Count of total deleted so far. */ function recursive_delete_pages($recno, $tablename, $graph = array()) { global $mydatabase, $deletedsofar, $dbtype; // if this is a text based database if ($dbtype == "txt-db-api") { return; } // if the recusive call was called without adding the starting // parent id to the list of ids seen add it here: if (count($graph) == 0) { $graph[] = $recno; } // if we have already removed 10,000 if ($deletedsofar > 10000) { return; } else { // Base case: this child has no children: $sqlquery = "SELECT recno FROM {$tablename} WHERE parentrec={$recno}"; $data = $mydatabase->query($sqlquery); if ($data->numrows() == 0) { // Delete this row: $sqlquery = "DELETE FROM {$tablename} WHERE recno={$recno}"; $mydatabase->query($sqlquery); $deletedsofar++; } else { // delete children: while ($row = $data->fetchRow(DB_FETCHMODE_ORDERED)) { // ahhh .. if a delete call has already been made for this parent // this Tree is actually a graph ! .. Don't endlessly loop: if (in_array($row[0], $graph)) { return; } else { // add child to list of id's seen: $graph[] = $row[0]; // recursion on removing children: recursive_delete_pages($row[0], $tablename, $graph); } // if in graph or array of ids already seen } // while more children } // if there are children } // if we have removed 10,0000 rows. }
if ($parent != 0) { $sqlquery = "SELECT pageurl FROM livehelp_visits_monthly WHERE recno='{$parent}' LIMIT 1"; $rs = $mydatabase->query($sqlquery); $row = $rs->fetchRow(DB_FETCHMODE_ORDERED); $pageurl = $row[0]; return "<a href={$pageurl} target=_blank>{$pageurl}</a>"; } else { return " END of Session"; } } // removes a page and its children. if (!empty($UNTRUSTED['removevisit'])) { $rec = intval($UNTRUSTED['removevisit']); $graph = array(); $graph[] = $rec; recursive_delete_pages($rec, 'livehelp_visits_monthly'); print "<font color=990000>{$deletedsofar} removed...</font><br>"; } $month = sprintf("%02d", intval($UNTRUSTED['month'])); $year = sprintf("%04d", intval($UNTRUSTED['year'])); $lastaction = date("Ymdhis"); $startdate = date("Ymd"); $expand_array = explode(",", $UNTRUSTED['expand']); if (empty($UNTRUSTED['parent'])) { $UNTRUSTED['parent'] = 0; } ?> <link title="new" rel="stylesheet" href="style.css" type="text/css"> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $lang['charset']; ?>
} if (empty($UNTRUSTED['perpage'])) { $UNTRUSTED['perpage'] = 25; } // if no admin rights then user can not clear or remove data: $query = "SELECT * FROM livehelp_users WHERE sessionid='" . $identity['SESSIONID'] . "'"; $data = $mydatabase->query($query); $row = $data->fetchRow(DB_FETCHMODE_ASSOC); $isadminsetting = $row['isadmin']; $myid = $row['user_id']; // removes a referer and its children. if (!empty($UNTRUSTED['removereferer'])) { $rec = intval($UNTRUSTED['removereferer']); $graph = array(); $graph[] = $rec; recursive_delete_pages($rec, 'livehelp_referers_monthly', $graph); print "<font color=990000>{$deletedsofar} removed...</font><br>"; } $month = sprintf("%02d", intval($UNTRUSTED['month'])); $year = sprintf("%04d", intval($UNTRUSTED['year'])); $lastaction = date("Ymdhis"); $startdate = date("Ymd"); $expand_array = explode(",", $UNTRUSTED['expand']); if (!empty($UNTRUSTED['whichdepartment'])) { $sqlquery = "SELECT user_id FROM livehelp_operator_departments WHERE user_id='{$myid}' AND department='" . intval($UNTRUSTED['whichdepartment']) . "' "; $data_check = $mydatabase->query($sqlquery); if ($UNTRUSTED['whichdepartment'] != 0 && $data_check->numrows() == 0) { $UNTRUSTED['whichdepartment'] = ""; } } // Select out the current months data: