Ejemplo n.º 1
0
function addNav()
{
    global $connection;
    if (isset($_GET['name']) && isset($_GET['pc'])) {
        $name = $connection->real_escape_string($_GET['name']);
        $parCan = $connection->real_escape_string($_GET['pc']);
        $parId = getCanonId($parCan);
        //get min id fron navcats and minus 1
        $query = "SELECT...";
        if ($result = $connection->query($query)) {
            $row = $result->fetch_assoc();
            $newId = (int) $row['navid'];
            $newId -= 1;
        } else {
            return 'false';
        }
        //create canonical name
        $nameCan = strtolower($name);
        $nameCan = str_replace(' ', '-', $nameCan);
        $nameCan = str_replace("'", '', $nameCan);
        //check for duplicate name
        if ($exisiting = checkExisting()) {
            if (in_array($nameCan, $exisiting)) {
                $i = 1;
                do {
                    $nameTest = $nameCan . '-' . $i++;
                } while (in_array($nameTest, $exisiting));
                $nameCan = $nameTest;
            }
        }
        $query = "INSERT...";
        if (!($result = $connection->query($query))) {
            return 'false';
        }
        //get rel order and add 1
        $query = "SELECT...";
        if ($result = $connection->query($query)) {
            $row = $result->fetch_assoc();
            $rel = (int) $row['rel_order'];
            $rel += 1;
        } else {
            return 'false';
        }
        $query = "INSERT INTO...";
        if (!($result = $connection->query($query))) {
            return 'false';
        }
        return $nameCan;
    } else {
        return 'false';
    }
}
Ejemplo n.º 2
0
 function walkTheCategories($canon, $active)
 {
     global $connection;
     global $DBErrorMsg;
     //query for canon children
     if ($active === '1') {
         //get deactivated nav
         $data = getNavData(3, $canon, true);
     } else {
         //get active nav
         $data = getNavData(1, $canon, true);
     }
     $parentId = getCanonId($canon);
     foreach ($data as $subCanon => $id) {
         //deactivate
         $query = "UPDATE...";
         if (!($result = $connection->query($query))) {
             echo databaseErrorMsg($DBErrorMsg);
         }
         //recursively find all children
         walkTheCategories($subCanon, $active);
     }
 }
Ejemplo n.º 3
0
if (isset($_GET['chcan']) && isset($_GET['pcan'])) {
    require_once '../includes/db_connection.php';
    function reactivate($chid, $pid)
    {
        global $connection;
        global $DBErrorMsg;
        $query = "UPDATE...";
        if ($result = $connection->query($query)) {
            return 'true';
        } else {
            return 'false';
        }
    }
    function getCanonId($canon)
    {
        global $connection;
        global $DBErrorMsg;
        $query = "SELECT...";
        if ($result = $connection->query($query)) {
            while ($row = $result->fetch_assoc()) {
                return $row['navcat_id'];
            }
        } else {
            echo databaseErrorMsg($DBErrorMsg);
        }
    }
    $chid = getCanonId($connection->real_escape_string($_GET['chcan']));
    $pid = getCanonId($connection->real_escape_string($_GET['pcan']));
    echo reactivate($chid, $pid);
}