function mycount($str) { // If string is null or 1 the lucky number is done if (strlen($str) < 2) { return $str; } else { $sum = 0; // Start the sum at 0 // Iterate through all the characters $length = strlen($str); for ($i = 0; $i < $length; ++$i) { // Check if they are a number if (is_numeric($str[$i])) { // Add the value to the sum $sum += intval($str[$i]); } } // Recursively calculate the lucky number return mycount(strval($sum)); } }
function createMxRecord($strDomain, $recordType, $recordValue, $MXpref) { $strContainer = $strDomain; $strOwner = $strDomain; $intTTL = $this->main->ttl; $intPreference = $MXpref; $intRecordClass = '1'; $strMailExchanger = $recordValue; $strServer = ""; $objWMIService = new COM("winmgmts://./root/MicrosoftDNS"); $colItems = $objWMIService->ExecQuery("Select * from MicrosoftDNS_MXType where domainname='{$strDomain}' and preference='{$MXpref}'"); if (mycount($colItems) > 0) { print "Already Exists/n"; throw new lxException("mx_rec_already_exist", ''); } $objItem = $objWMIService->Get("MicrosoftDNS_MXType"); $errResult = $objItem->CreateInstanceFromPropertyData($strServer, $strContainer, $strOwner, $intReCordClass, $intTTL, $intPreference, $strMailExchanger); }
function checkForTemplateIssues($templatePath, $templateName, &$issues) { $content = file_get_contents($templatePath . "index.php"); $reqd = array("\$CONTENT", "\$ACTIONBARMODULE", "\$ACTIONBARPAGE", "\$SITEDESCRIPTION", "\$SITEKEYWORDS", "\$FOOTER", "\$ERRORSTRING", "\$WARNINGSTRING", "\$INFOSTRING"); // $nreqd = array("\$STARTSCRIPTS","\$TITLE","\$BREADCRUMB","\$DEBUGINFO","\$MENUBAR","\$INHERITEDINFO",); $nreqd = array("\$STARTSCRIPTS", "\$TITLE", "\$BREADCRUMB", "\$MENUBAR"); $id = 0; $i = 0; $j = 0; foreach ($reqd as $var) { switch (mycount($content, $var)) { case 0: addfatalissue($issues, "{$var} is missing", $id); $i = 1; $id++; break; case 1: break; default: addissue($issues, "{$var} is more than once", $id); $j = 1; $id++; } } foreach ($nreqd as $var) { switch (mycount($content, $var)) { case 0: addissue($issues, "{$var} is missing", $id); $j = 1; $id++; break; case 1: break; default: addissue($issues, "{$var} is more than once", $id); $j = 1; $id++; } } return array($i, $j); //returns 1 more than number of issues. see id getting incremented for every issue. }
function checkForModuleIssues($modulePath, $moduleName, &$issues) { $id = 1; $i = 0; $j = 0; if (!file_exists($modulePath . "moduleTables.txt")) { addFatalIssue($issues, "Module Info file is missing", $id++); $i = 1; } if (!file_exists($modulePath . $moduleName . ".lib.php")) { addFatalIssue($issues, "The module file is corrupt, Please download a fresh copy of the module", $id++); $i = 1; } else { $content = file_get_contents($modulePath . $moduleName . ".lib.php"); $reqd = array("class " . $moduleName . " implements module", "public function getHtml", "public function createModule", "public function deleteModule", "public function copyModule"); foreach ($reqd as $var) { switch (mycount($content, $var)) { case 0: addFatalIssue($issues, "{$var} is missing", $id); $i = 1; $id++; break; case 1: break; default: addFatalIssue($issues, "{$var} is more than once", $id); $i = 1; $id++; } } } if (!file_exists($modulePath . $moduleName . ".sql")) { addIssue($issue, "No sql file found", $id++); $j = 1; } return array($i, $j); }
$users = get_studentsbyfullname($course->id, $lastn, $firstn); if ($users === false) { $users = get_studentsbysimilarfirstname($course->id, $lastn, $firstn); if ($users === false && $nfirst > 1) { $i = 0; $users = array(); while ($i < $nfirst) { $users2 = get_studentsbysimilarfirstname($course->id, $lastn, $firstns[$i]); if ($users2) { $users = array_merge((array) $users, (array) $users2); } $i++; } } } $nuser = mycount($users); if ($nuser == 0) { echo '<p class="error"><b>' . $noext[0] . '</b> : ' . get_string('usernotfound', 'diplome') . '.</p>'; } else { if ($nuser == 1) { $diploma = get_record('diplome_diploma', 'userid', $users[key($users)]->id, 'courseid', $course->id); if ($diploma === false) { $diprecord = new object(); $diprecord->userid = $users[key($users)]->id; $diprecord->courseid = $course->id; } else { if ($diploma->status == 2) { echo '<p class=error><b>' . $noext[0] . '</b> : ' . get_string('alreadyprinted', 'diplome') . '</p>'; continue; } }