Пример #1
0
 public function initFor(WOOOF $wo)
 {
     $wooofUserId = $wo->userData['id'];
     if (!$wo->hasContent($wooofUserId)) {
         $wo->logError(self::_ECP . "0010 No value found for 'wooofUserId'");
         return false;
     }
     if ($wooofUserId === '0123456789') {
         return true;
     }
     $movieRamaPersonRow = $wo->db->getRowByColumn('v_movierama_persons', 'VUS_userId', $wooofUserId);
     if ($movieRamaPersonRow === FALSE) {
         return FALSE;
     }
     if ($movieRamaPersonRow === NULL) {
         $wo->logError(self::_ECP . "0020 User [{$wooofUserId}] should not be logged-in");
         return false;
     }
     $this->userId = $movieRamaPersonRow['VUS_id'];
     $this->personProfileId = $movieRamaPersonRow['VUS_personProfileId'];
     $this->userSlug = $movieRamaPersonRow['PROF_firstName'] . ' ' . $movieRamaPersonRow['PROF_lastName'];
     $this->movieRamaPersonRow = $movieRamaPersonRow;
     $this->isUserRegistered = $movieRamaPersonRow['VUS_isVerified'] == '1';
     return $this->userId;
 }
Пример #2
0
 public static function get(WOOOF $wo, $paramCode, $evenDeleted = false)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     $p_param = trim(strtoupper($paramCode));
     if (isset(self::$params[$paramCode])) {
         return self::$params[$paramCode][0];
     }
     $t1 = new WOOOF_dataBaseTable($wo->db, 'sys_params');
     if (!$t1->constructedOk) {
         return false;
     }
     $wheres = ['code' => $paramCode];
     if (!$evenDeleted) {
         $wheres['isDeleted'] = 0;
     }
     $res = $t1->getResult($wheres, 'code');
     if ($res === FALSE) {
         return false;
     }
     if ($res['rowsFetched'] !== 1) {
         $wo->logError(self::_ECP . "0010 {$res['rowsFetched']} records found for [{$paramCode}]");
         return false;
     }
     $paramRec = $t1->resultRows[0];
     $l_val = self::convertToType($paramRec['paramValue'], $paramRec['paramDataType']);
     self::$params[$paramCode] = array($l_val, $paramRec['paramDataType']);
     return $l_val;
 }
Пример #3
0
 /**
  *
  * @param WOOOF $wo
  * @param VO_TblFlagItems $obj
  * @param char $action
  * @param bool $fetchBack
  * @return false | type of reported object
  * Returns actually saved $obj if $fetchBack is set to true
  */
 public static function save(WOOOF $wo, VO_TblFlagItems &$obj, $action = 'I', $fetchBack = true)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     $wo->debug("{$place}:  ");
     if (!$wo->hasContent($obj->flaggedByUserId)) {
         $wo->logError(self::_ECP . "3011 No value provided for [flaggedByUserId]");
         return false;
     }
     if (!$wo->hasContent($obj->whatId)) {
         $wo->logError(self::_ECP . "3012 No value provided for [whatId]");
         return false;
     }
     if (!$wo->hasContent($obj->whatType)) {
         $wo->logError(self::_ECP . "3013 No value provided for [whatType]");
         return false;
     }
     if ($obj->flaggedByUserId === $obj->whatId) {
         $wo->logError(self::_ECP . "3014 Id's cannot be the same");
         return false;
     }
     $tblFlagItems = new WOOOF_dataBaseTable($wo->db, 'flag_items');
     if ($tblFlagItems === FALSE) {
         return false;
     }
     //insert
     if ($action === 'I') {
         $obj->flaggedDateTime = WOOOF::currentGMTDateTime();
         $newId = $tblFlagItems->insertRowFromArraySimple($obj->toArray());
         if ($newId === FALSE) {
             return false;
         }
     } else {
         $obj->flaggedDateTime = $wo->currentGMTDateTime();
         $res = $tblFlagItems->updateRowFromArraySimple($obj->toArray());
         if ($res === FALSE) {
             return false;
         }
     }
     return $obj->whatType;
 }
Пример #4
0
 /**
  *
  * @param WOOOF $wo
  * @param array $in
  * @return boolean
  */
 public static function passwordChange(WOOOF $wo, $in)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     $wo->debug("{$place}:  ChangePassword");
     $movieRamaPerson = $wo->db->getRowByColumn('v_movierama_persons', 'VUS_id', $in['movieRamaUserId']);
     if ($movieRamaPerson === FALSE) {
         return false;
     }
     if ($movieRamaPerson === NULL) {
         $wo->logError(self::_ECP . "3352 No MovieRama person found.");
         return false;
     }
     $user = $wo->db->getRow('__users', $movieRamaPerson['VUS_userId']);
     if ($user === FALSE) {
         return false;
     }
     if ($user === NULL) {
         $wo->logError(self::_ECP . "3357 No user found.");
         return false;
     }
     //change password here
     $passwordErrors = [];
     $res = WOOOF_User::changePassword($wo, $user['loginName'], $in['newPass'], $passwordErrors, $in['oldPass']);
     if ($res === FALSE) {
         return false;
     }
     return $res;
 }
 /**
  *
  * @param WOOOF $wo
  * @param string $externalFileId
  * @return false | null | array	// return contents of row in table
  */
 public static function getExternalFileDataById(WOOOF $wo, $externalFileId)
 {
     if (!$wo->hasContent($externalFileId)) {
         $wo->logError(self::_ECP . "0290 No value provided for 'externalFileId'.");
         return FALSE;
     }
     $result = $wo->db->getRow('__externalFiles', $externalFileId);
     return $result;
     //return all row
 }
Пример #6
0
 /**
  *
  * @param WOOOF $wo
  * @param string $id for record to be deleted
  * @param string $action ('unLike' | 'unHate')
  * @return id of row deleted
  */
 public static function deleteOpinion(WOOOF $wo, $id, $action)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     $wo->debug("{$place}:  Delete Movie Opinion");
     if (!$wo->hasContent($id)) {
         $wo->logError(self::_ECP . "1909 No value provided for [id]");
         return false;
     }
     $tblUserMovieOpinions = new WOOOF_dataBaseTable($wo->db, 'movierama_user_movies_opinions');
     if (!$tblUserMovieOpinions->constructedOk) {
         return false;
     }
     //find movie id to update counter
     $movieOpinionRec = $wo->db->getRow('movierama_user_movies_opinions', $id);
     if ($movieOpinionRec === FALSE) {
         return false;
     }
     $res = $tblUserMovieOpinions->deleteRow($id);
     if ($res === FALSE) {
         return false;
     }
     if ($action === 'unLike') {
         $decreaseLike = self::updateCounter($wo, $movieOpinionRec['movieId'], 'noOfLikes', '-1');
         if ($decreaseLike === FALSE) {
             return false;
         }
     } else {
         if ($action === 'unHate') {
             $decreaseHate = self::updateCounter($wo, $movieOpinionRec['movieId'], 'noOfHates', '-1');
             if ($decreaseHate === FALSE) {
                 return false;
             }
         }
     }
     return $id;
 }
Пример #7
0
 /**
  *
  * @param WOOOF $wo
  * @param string $evaluationId
  * @param string $requestorUserId
  * return [] if none | [ criteria1, criteria2, ... ]
  */
 public static function getCriteria(WOOOF $wo, $evaluationId, $requestorUserId)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     if (!$wo->hasContent($evaluationId)) {
         $wo->logError(self::_ECP . "5099 No value for evaluation id to find criteria");
         return false;
     }
     $criterias = [];
     $criteriaElems = ['id', 'evaluationId', 'evalTemplateId', 'label', 'description', 'evaluationTypeDVCode', 'isOptional', 'weight'];
     $tblEvaluationCriteria = new WOOOF_dataBaseTable($wo->db, 'evaluation_criteria');
     if (!$tblEvaluationCriteria->constructedOk) {
         return false;
     }
     $safeEvaluationId = $wo->db->escape($evaluationId);
     $result = $wo->db->query("SELECT * FROM evaluation_criteria WHERE evaluationId='{$safeEvaluationId}' AND isDeleted='0'");
     if ($result === FALSE) {
         return false;
     }
     if (!$wo->db->getNumRows($result)) {
         //no error no results
         return [];
     } else {
         //no error results
         while ($row = $wo->db->fetchAssoc($result)) {
             $tblEvaluationCriteria->resultRows[] = $row;
         }
     }
     foreach ($tblEvaluationCriteria->resultRows as $aCriteria) {
         $criteria = [];
         WOOOF_Util::filterOnKeys($criteria, $criteriaElems, $aCriteria);
         $criterias[] = $criteria;
     }
     return $criterias;
 }
Пример #8
0
 /**
  *
  * @param WOOOF $wo
  * @param string $databaseName
  * @param string $tableName
  * @param bool $execute		// Optional, default is false. Set to true to actually execute the statements
  * @return false|true|array	// true on successful execution of statements. array if execute=false
  */
 public static function buildIndexesForTable(WOOOF $wo, $databaseName, $tableName, $execute = false)
 {
     $lc_legalPattern = '/^([piuts])([A-Z])([1-9])([ad])?$/';
     // Type of index: p -> primary, i -> index, u -> unique, t -> fullText, s -> spatial
     // 'Name' of index: just a different letter for each index
     // Position: of column to the specified index
     // Collation: (optional) a -> ASC, d -> DESC (not implemented in MySQL!!)
     //echo '<h2>'.__CLASS__.'.'.__FUNCTION__.'</h2>';
     $sql = "\n\t\t\tselect c.name, c.indexParticipation\n\t\t\tfrom __tableMetaData t, __columnMetaData c\n\t\t\twhere t.tableName = '{$tableName}' and c.tableId = t.id and c.indexParticipation is not null and c.indexParticipation != ''\n\t\t";
     $ipResults = $wo->db->query($sql);
     if ($ipResults === FALSE) {
         $wo->logError(self::_ECP . "0135 You may need to WOOOF_MetaData:selfUpgradeMetaData your db first!");
         return FALSE;
     }
     $indexesArray = array();
     // hold the columns: array( iName => array( [0] => array( colName, collation ), ... ), ... )
     $indexesArray2 = array();
     // hold the type: array( iName => iType )
     $dbIndexesArray = array();
     $dbIndexesArray2 = array();
     while (($aResult = $wo->db->fetchAssoc($ipResults)) !== NULL) {
         // $aResult: array( name, indexParticipation )
         //var_dump($aResult);
         $colName = $aResult['name'];
         $indexParticipationsArray = explode(',', $aResult['indexParticipation']);
         foreach ($indexParticipationsArray as $anIndexParticipationString) {
             $anIndexParticipationString = trim($anIndexParticipationString);
             if (!$wo->hasContent($anIndexParticipationString)) {
                 continue;
             }
             $matches = null;
             $matchOk = preg_match($lc_legalPattern, $anIndexParticipationString, $matches);
             if ($matchOk === 0 or $matchOk === FALSE) {
                 $wo->logError(self::_ECP . "0100 Bad IndexParticipation value [{$anIndexParticipationString}] for column [{$tableName}.{$colName}]");
                 return FALSE;
             }
             // var_dump($matches);
             list($dummy, $iType, $iName, $iSeq) = $matches;
             $iCollation = $wo->getFromArray($matches, 4);
             if (isset($indexesArray[$iName][$iSeq])) {
                 $wo->logError(self::_ECP . "0105 Multiple columns ([{$colName}], [{$indexesArray[$iName][$iSeq][0]}]) with same sequence number [{$iSeq}] for index [{$iName}] on column [{$tableName}.{$colName}]");
                 return FALSE;
             }
             $indexesArray[$iName][$iSeq] = array($colName, $iCollation);
             if (!isset($indexesArray2[$iName])) {
                 $indexesArray2[$iName] = $iType;
             } else {
                 if ($indexesArray2[$iName] != $iType) {
                     $wo->logError(self::_ECP . "0110 Index [{$iName}] of column [{$tableName}.{$colName}] defined with multiple types: [{$iType}] and [{$indexesArray2[$iName]}]");
                     return false;
                 }
             }
         }
         // foreach one of the column's participations
     }
     // foreach column with indexParticipation(s)
     //var_dump($indexesArray);
     if (count($indexesArray) == 0) {
         return $execute ? true : array();
     }
     // Load existing indexes
     //
     $dbIndTemp = self::getDBIndexesForTable($wo, $databaseName, $tableName);
     if ($dbIndTemp === FALSE) {
         return FALSE;
     }
     list($dbIndexesArray2, $dbIndexesArray) = $dbIndTemp;
     $sqlStatements = array();
     foreach ($indexesArray as $anIndexCode => &$anIndexColumns) {
         //echo "$anIndexCode<br>";
         $sqlOut = '';
         $indexName = $tableName . '_idx' . $anIndexCode;
         ksort($anIndexColumns);
         // sort according to specified position and not leave according to order of entry in the array
         // Check if already built/exists in DB
         //
         $needToRecreateIndex = false;
         $needToCreateIndex = false;
         if (isset($dbIndexesArray2[$anIndexCode])) {
             if ($dbIndexesArray2[$anIndexCode] == $indexesArray2[$anIndexCode]) {
                 if (count($dbIndexesArray[$anIndexCode]) == count($indexesArray[$anIndexCode])) {
                     $i = 1;
                     foreach ($anIndexColumns as $aColumn) {
                         if ($aColumn[0] == $dbIndexesArray[$anIndexCode][$i][0]) {
                             // ignore collation differences as collation is a joke (ASC only) in MySQL
                         } else {
                             $needToRecreateIndex = true;
                             break;
                         }
                         // same column or not in that position
                         $i++;
                     }
                     // foreach column in index
                 } else {
                     $needToRecreateIndex = true;
                 }
                 // count of cols same or not
             } else {
                 $needToRecreateIndex = true;
             }
             // index type same or not
         } else {
             $needToCreateIndex = true;
         }
         // var_dump($needToRecreateIndex, $needToCreateIndex);
         if ($needToRecreateIndex) {
             $sqlStatements[] = "ALTER TABLE `{$tableName}` DROP INDEX `{$indexName}`;";
         }
         if ($needToCreateIndex or $needToRecreateIndex) {
             $sqlOut .= "ALTER TABLE `{$tableName}` ADD ";
             switch ($indexesArray2[$anIndexCode]) {
                 case 'p':
                     $sqlOut .= "CONSTRAINT PRIMARY KEY ";
                     break;
                 case 'u':
                     $sqlOut .= "UNIQUE KEY `{$indexName}` ";
                     break;
                 case 'i':
                     $sqlOut .= "INDEX `{$indexName}` ";
                     break;
                 case 's':
                     $sqlOut .= "SPATIAL INDEX `{$indexName}` ";
                     break;
                 case 't':
                     $sqlOut .= "FULLTEXT INDEX `{$indexName}` ";
                     break;
                 default:
                     $sqlOut .= " " . $indexesArray2[$anIndexCode] . " ***not implemented*** ";
             }
             $sqlOut .= '( ';
             foreach ($anIndexColumns as $aColumn) {
                 $sqlOut .= "`" . $aColumn[0] . "` ";
                 if (isset($aColumn[1])) {
                     $sqlOut .= ' ' . ($aColumn[1] == 'd' ? 'DESC' : 'ASC');
                 }
                 $sqlOut .= ', ';
             }
             // foreach column
             $sqlOut = substr($sqlOut, 0, -2);
             $sqlOut .= ' ) ';
             $sqlOut .= ';';
             $sqlStatements[] = $sqlOut;
         }
         // create index
     }
     // foreach index
     // var_dump($sqlStatements);
     if ($execute) {
         if (count($sqlStatements) > 0) {
             $succ = $wo->db->queryMultiple($sqlStatements);
             return $succ;
         } else {
             return true;
         }
     }
     return $sqlStatements;
 }
 /**
  *
  * @param WOOOF $wo
  * @param array $in	// [ 'email' ]
  * @return array [ 'resendOk', 'errors' ]
  */
 public static function resendToken(WOOOF $wo, $in)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     $requestedAction = 'resendToken';
     $pageLocation = '3';
     $browserTitle = 'MovieRama User Verification Token Resend';
     if ($wo->userData['id'] != '0123456789') {
         $wo->handleShowStopperError("505 {$place}: " . $wo->userData['id']);
     }
     if (!$wo->hasContent($in['email'])) {
         $wo->logError(self::_ECP . "2359 You must provide your email in order to resend your verification token.");
         return false;
     }
     $movieramaUserRec = $wo->db->getRowByColumn('movierama_users', 'username', $in['email']);
     if ($movieramaUserRec === FALSE) {
         return false;
     }
     if ($movieramaUserRec === NULL) {
         $wo->logError(self::_ECP . "2360 I am sorry it seems you are not a registered MovieRama user.");
         return false;
     }
     $res = VO_Registration::tokenResend($wo, $in);
     if ($res === FALSE) {
         $out = ['resendOk' => false, 'errors' => $wo->getErrorsAsArrayAndClear()];
         $wo->db->rollback();
     } else {
         $out = ['resendOk' => true, 'resend' => $res];
         $wo->db->commit();
     }
     return $out;
 }
Пример #10
0
 /**
  *
  * @param WOOOF $wo
  * @param array $in [array of user answers to eval criteria]
  * @return false | [ 'evaluationSavedOk' => bool, 'evaluationSavedForEvalId' => string ]
  */
 public static function submitEvaluation(WOOOF $wo, $in)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     if ($wo->userData['id'] == '0123456789') {
         $wo->handleShowStopperError('505');
     }
     if (!$wo->hasContent($in)) {
         $wo->logError(self::_ECP . "1226 You must provide data to submit an evaluation");
         return false;
     }
     $res = VO_Evaluation::submitEval($wo, $in, $wo->app->userId);
     if ($res === FALSE) {
         $out = ['evaluationSavedOk' => false, 'errors' => $wo->getErrorsAsArrayAndClear()];
         $wo->db->rollback();
     } else {
         $out = ['evaluationSavedOk' => true, 'evaluationSavedForEvalId' => $res];
         $wo->db->commit();
     }
     return $out;
 }
Пример #11
0
 /**
  *
  * @param WOOOF $wo
  * @param array $in
  * @return false | [ 'flagItemOk' => bool, 'flagItemRecType' => string, 'errors' => array ]
  */
 public static function flagMovie(WOOOF $wo, $in)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     if ($wo->userData['id'] == '0123456789') {
         $wo->handleShowStopperError('505');
     }
     if (!$wo->hasContent($in['whatId'])) {
         $wo->logError(self::_ECP . "4196 You must provide a movie ID to report!");
         return false;
     }
     if (!$wo->hasContent($in['whatType'])) {
         $wo->logError(self::_ECP . "4197 You must provide a target type to report!");
         return false;
     }
     if (!$wo->hasContent($in['flagText'])) {
         $wo->logError(self::_ECP . "4198 You must provide flag text!");
         return false;
     }
     $res = VO_FlagItem::saveFlagItem($wo, $wo->app->userId, $in);
     if ($res === FALSE) {
         $out = ['flagItemOk' => false, 'errors' => $wo->getErrorsAsArrayAndClear()];
         $wo->db->rollback();
     } else {
         $out = ['flagItemOk' => true, 'flagItemRecType' => $res];
         $wo->db->commit();
     }
     return $out;
 }
Пример #12
0
 /**
  * 
  * @param WOOOF $wo
  * @param string $domain
  * @param bool $isFullDomain
  * @return false | string
  */
 public static function formFullURL(WOOOF $wo, $domain, $isFullDomain = false)
 {
     if (!$wo->hasContent($domain)) {
         $wo->logError(self::_ECP . "0910 No value provided for [domain]");
         return false;
     }
     $domain = trim($domain);
     $dotParts = explode('.', $domain);
     $noOfParts = count($dotParts);
     $i = $noOfParts;
     while ($i > 2) {
         $i--;
         array_shift($dotParts);
     }
     $domain = implode('.', $dotParts);
     if (substr($domain, 0, 4) === 'http') {
         $fullURL = $domain;
     } else {
         if (!$isFullDomain and substr($domain, 0, 4) != 'www.') {
             $fullURL = 'www.' . $domain;
         }
         $fullURL = 'http://' . $domain;
     }
     return $fullURL;
 }
Пример #13
0
 /**
  * 
  * @param WOOOF $wo
  * @param string $loginName
  * @param string $newPassword
  * @param string[] &$passwordErrors	// return possible new password problems
  * @param string $oldPassword		// Optional, default '', do not verify old pass validity
  * @param string $checkPassword		// Optional, default true. Check new pass is ok
  * @return boolean
  */
 public static function changePassword(WOOOF $wo, $loginName, $newPassword, &$passwordErrors, $oldPassword = '', $checkPassword = true)
 {
     $passwordErrors = array();
     if (!$wo->hasContent($loginName) or !$wo->hasContent($newPassword)) {
         $wo->logError('7055 Both loginName and mew Password must be provided');
         return false;
     }
     $userRes = $wo->db->query("select * from __users where loginName='{$loginName}'");
     if ($userRes === FALSE) {
         return FALSE;
     }
     $userRow = $wo->db->fetchAssoc($userRes);
     if ($userRow === NULL) {
         $wo->logError(self::_ECP . "0057 User with loginName [{$loginName}] was not found");
         return FALSE;
     }
     if ($userRow['id'] == self::ID_OF_NOT_LOGGED_IN) {
         $wo->logError(self::_ECP . "0059 Cannot changePassword of this user");
         return FALSE;
     }
     if ($wo->hasContent($oldPassword)) {
         $oldPassHashed = $wo->getPasswordHash($oldPassword, $userRow['id']);
         if ($oldPassHashed === FALSE or $oldPassHashed != $userRow['loginPass']) {
             $wo->logError(self::_ECP . "0060 Bad old password was given");
             return false;
         }
     }
     if ($checkPassword) {
         if ($wo->evaluatePassword($newPassword, $newPassword, $passwordErrors) === FALSE) {
             $wo->logError(self::_ECP . "0063 Password is not accepted");
             return FALSE;
         }
     }
     $newPassHashed = $wo->getPasswordHash($newPassword, $userRow['id']);
     if ($newPassHashed === FALSE) {
         return FALSE;
     }
     $newPassHashed = $wo->db->escape($newPassHashed);
     $succ = $wo->db->query("update __users set loginPass = '******' where id = '{$userRow['id']}'");
     if ($succ === FALSE) {
         return FALSE;
     }
     return true;
 }
Пример #14
0
 /**
  *
  * @param WOOOF $wo
  * @param array $in
  * @return boolean
  */
 public static function tokenResend(WOOOF $wo, $in)
 {
     $place = __CLASS__ . '::' . __FUNCTION__;
     $wo->debug("{$place}:  ReseendVerificationToken");
     $movieramaUserRec = $wo->db->getRowByColumn('movierama_users', 'username', $in['email']);
     if ($movieramaUserRec === FALSE) {
         return false;
     }
     if ($movieramaUserRec === NULL) {
         $wo->logError(self::_ECP . "2370 No such user found.");
         return false;
     }
     if ($wo->hasContent($movieramaUserRec['verificationToken'])) {
         $succ = VO_Users::handleVerificationToken($wo, $movieramaUserRec['id'], $movieramaUserRec['username'], $movieramaUserRec['verificationToken']);
         if ($succ === FALSE) {
             return FALSE;
         }
     } else {
         $wo->logError(self::_ECP . "2380 It seems you have already been verified.");
         return false;
     }
     return $succ;
 }