add_error("Invalid quiz question ID");
                                 application_log("API passed [" . $question_id . "] which is an invalid question ID.");
                             }
                         }
                     } else {
                         add_error("No question IDs were passed to delete.");
                     }
                 } else {
                     add_error("Invalid quiz question ID.");
                 }
                 if (!$ERROR && !empty($PROCESSED["qquestion_ids"])) {
                     foreach ($PROCESSED["qquestion_ids"] as $question_id) {
                         $qquestion = Models_Quiz_Question::fetchRowByID($question_id);
                         if (!$qquestion->fromArray(array("question_active" => "0"))->update()) {
                             add_error("Failed to deactivate question.");
                             applicaiton_log("Failed to deactivate quiz question, DB said: " . $db->ErrorMsg());
                         }
                     }
                     if (!$ERROR) {
                         echo json_encode(array("status" => "success", "data" => array("qquestion_ids" => $PROCESSED["qquestion_ids"])));
                     } else {
                         echo json_encode(array("status" => "error", "data" => array("Failed to delete quiz question.")));
                     }
                 }
                 break;
         }
         break;
     case "GET":
         break;
 }
 exit;
function google_create_id()
{
    global $db, $GOOGLE_APPS, $AGENT_CONTACTS, $ERROR, $ERRORSTR, $ENTRADA_USER;
    if (isset($GOOGLE_APPS) && is_array($GOOGLE_APPS) && isset($GOOGLE_APPS["active"]) && (bool) $GOOGLE_APPS["active"]) {
        $query = "\tSELECT a.*, b.`group`, b.`role`\n\t\t\t\t\tFROM `" . AUTH_DATABASE . "`.`user_data` AS a\n\t\t\t\t\tLEFT JOIN `" . AUTH_DATABASE . "`.`user_access` AS b\n\t\t\t\t\tON a.`id` = b.`user_id`\n\t\t\t\t\tWHERE a.`id` = " . $db->qstr($ENTRADA_USER->getID());
        $result = $db->GetRow($query);
        if ($result) {
            if (isset($GOOGLE_APPS["groups"]) && is_array($GOOGLE_APPS["groups"]) && in_array($_SESSION["details"]["group"], $GOOGLE_APPS["groups"])) {
                if ($result["google_id"] == "opt-out" || $result["google_id"] == "opt-in" || $result["google_id"] == "") {
                    if ($google_id = google_generate_id($result["firstname"], $result["lastname"])) {
                        require_once "Zend/Loader.php";
                        Zend_Loader::loadClass("Zend_Gdata_ClientLogin");
                        Zend_Loader::loadClass("Zend_Gdata_Gapps");
                        $firstname = $result["firstname"];
                        $lastname = $result["lastname"];
                        $password = $result["password"];
                        try {
                            $client = Zend_Gdata_ClientLogin::getHttpClient($GOOGLE_APPS["admin_username"], $GOOGLE_APPS["admin_password"], Zend_Gdata_Gapps::AUTH_SERVICE_NAME);
                            $service = new Zend_Gdata_Gapps($client, $GOOGLE_APPS["domain"]);
                            $service->createUser($google_id, $firstname, $lastname, $password, "SHA-1");
                            $search = array("%FIRSTNAME%", "%LASTNAME%", "%GOOGLE_APPS_DOMAIN%", "%GOOGLE_ID%", "%GOOGLE_APPS_QUOTA%", "%APPLICATION_NAME%", "%ADMINISTRATOR_NAME%", "%ADMINISTRATOR_EMAIL%");
                            $replace = array($firstname, $lastname, $GOOGLE_APPS["domain"], $google_id, $GOOGLE_APPS["quota"], APPLICATION_NAME, $AGENT_CONTACTS["administrator"]["name"], $AGENT_CONTACTS["administrator"]["email"]);
                            $subject = str_replace($search, $replace, $GOOGLE_APPS["new_account_subject"]);
                            $message = str_replace($search, $replace, $GOOGLE_APPS["new_account_msg"]);
                            $query = "UPDATE `" . AUTH_DATABASE . "`.`user_data` SET `google_id` = " . $db->qstr($google_id) . " WHERE `id` = " . $db->qstr($ENTRADA_USER->getID());
                            if ($db->Execute($query)) {
                                if (@mail($_SESSION["details"]["email"], $subject, $message, "From: \"" . $AGENT_CONTACTS["administrator"]["name"] . "\" <" . $AGENT_CONTACTS["administrator"]["email"] . ">\nReply-To: \"" . $AGENT_CONTACTS["administrator"]["name"] . "\" <" . $AGENT_CONTACTS["administrator"]["email"] . ">")) {
                                    $_SESSION["details"]["google_id"] = $google_id;
                                    application_log("success", "Successfully sent new Google account notice to " . $_SESSION["details"]["email"]);
                                    return true;
                                } else {
                                    applicaiton_log("error", "Unable to send new Google account notification to " . $_SESSION["details"]["email"]);
                                    throw new Exception();
                                }
                            } else {
                                application_log("error", "Unable to update the google_id [" . $google_id . "] field for proxy_id [" . $ENTRADA_USER->getID() . "].");
                                throw new Exception();
                            }
                        } catch (Zend_Gdata_Gapps_ServiceException $e) {
                            if (is_array($e->getErrors())) {
                                foreach ($e->getErrors() as $error) {
                                    application_log("error", "Unable to create google_id [" . $google_id . "] for username [" . $_SESSION["details"]["username"] . "]. Error details: [" . $error->getErrorCode() . "] " . $error->getReason() . ".");
                                }
                            }
                        }
                    } else {
                        application_log("error", "google_generate_id() function returned false out of firstname [" . $result["firstname"] . " and lastname [" . $result["lastname"] . "].");
                    }
                }
            } else {
                application_log("error", "google_create_id() failed because users group [" . $_SESSION["details"]["group"] . "] was not in the GOOGLE_APPS[groups].");
            }
        } else {
            application_log("error", "google_create_id() failed because we were unable to generate information on proxy_id [" . $ENTRADA_USER->getID() . "]. Database said: " . $db->ErrorMsg());
        }
    }
    $ERROR++;
    $ERRORSTR[] = "We apologize, but we were unable to create your <strong>" . $GOOGLE_APPS["domain"] . "</strong> account for you at this time.<br /><br />The system administrator has been notified of the error; please try again later.";
    return false;
}