<?php include 'config.php'; setlocale(LC_ALL, 'en_US.UTF8'); function clearUTF($s) { $r = ''; $s1 = iconv('UTF-8', 'ASCII//TRANSLIT', $s); for ($i = 0; $i < strlen($s1); $i++) { $ch1 = $s1[$i]; $ch2 = mb_substr($s, $i, 1); $r .= $ch1 == '?' ? $ch2 : $ch1; } return $r; } $words = new Dase_DBO_Word($db); foreach ($words->findAll(1) as $word) { $sub = array(); $sub[] = $word->simplified; $sub[] = $word->traditional; $sub[] = $word->pinyin; $sub[] = clearUTF($word->pinyin); $word->search_bag = join(' ', $sub); print $word; $word->update(); }
} } //Update transaction $sql->query("\n\t\t \tUPDATE transactions\n\t\t\tSET description='" . $data['description'] . "',\n\t\t\t\tamount='" . $data['amount'] . "',\n\t\t\t\tdate='" . $data['date'] . "',\n\t\t\t\taccount_to_id='" . $data['accountTo'] . "',\n\t\t\t\taccount_from_id='" . $data['accountFrom'] . "',\n\t\t\t\ttransaction_type_id='" . $data['transType'] . "'\n\t\t\tWHERE transactions.id = '" . $data['transactionId'] . "'\n\t\t "); //Remove tags relationship $sql->query("\n\t\t \tDELETE FROM transactions_has_tags\n\t\t\tWHERE transaction_id='" . $data['transactionId'] . "'\n\t\t "); //Insert tags if ($data['tags'] != "" || $data['tags'] != NULL) { foreach ($tags->get() as $tag) { if (in_array(trim(strtolower(clearUTF($tag['name']))), $transactionTagsCompare)) { //IF have in BD $sql->query("\n\t\t\t\t\t\tINSERT INTO transactions_has_tags(transaction_id,tag_id)\n\t\t\t\t\t\tVALUES('" . $data['transactionId'] . "','" . $tag['id'] . "')\n\t\t\t\t\t"); } } foreach ($transactionTags as $tag) { if (!in_array(strtolower(clearUTF(trim($tag))), $allTagsCompare)) { //IF DONT have in BD $sql->query("\n\t\t\t\t\t\tINSERT INTO tags(name, profile_id)\n\t\t\t\t\t\tVALUES ('" . trim(convertToUnicode($tag)) . "','" . CurrentUser::getId() . "')\n\t\t\t\t\t"); $tagId = $sql->insertId; $sql->query("\n\t\t\t\t\t\tINSERT INTO transactions_has_tags(transaction_id,tag_id)\n\t\t\t\t\t\tVALUES('" . $data['transactionId'] . "','" . $tagId . "')\n\t\t\t\t\t"); } } } //Add in Ammount if ($data['accountTo'] != '') { $balance = $accounts->get(1, $data['accountFrom'], 'balance'); $balance += $oldData[0]['amount']; $balance += $data['amount']; $sql->query("UPDATE accounts SET balance='" . $balance . "' WHERE id = '" . $data['accountFrom'] . "'"); $balance = $accounts->get(1, $data['accountTo'], 'balance'); $balance -= $oldData[0]['amount'];
<?php include 'config.php'; setlocale(LC_ALL, 'en_US.UTF8'); function clearUTF($s) { $r = ''; $s1 = iconv('UTF-8', 'ASCII//TRANSLIT', $s); for ($i = 0; $i < strlen($s1); $i++) { $ch1 = $s1[$i]; $ch2 = mb_substr($s, $i, 1); $r .= $ch1 == '?' ? $ch2 : $ch1; } return $r; } echo clearUTF('Šíleně žluťoučký Vašek úpěl olol! This will remain untranslated: ᾡᾧῘઍિ૮'); //outputs Silene zlutoucky Vasek upel olol! This will remain untranslated: ᾡᾧῘઍિ૮
function prepareToCompare($term) { return strtolower(clearUTF(trim($term))); }
case 'put': //Requisições $_DATA = $request->getRequestVars(); //Informações cadastradas $data = array('tagName' => trim($_DATA['tagName'])); //Instâncias $tags = new Tags(); //Verificar inputs básicos if ($data['tagName'] == '' || count($data['tagName']) > 28) { //Nome da tag RestUtils::sendResponse('406', array('data' => 'tagName', 'message' => 'Por favor, verifique o nome da tag.')); } //Verifica se a tag já não existe $allTagsCompare = array(); foreach ($tags->get(500) as $tag) { $tag = strtolower(clearUTF($tag['name'])); array_push($allTagsCompare, $tag); } if (in_array(prepareToCompare($data['tagName']), $allTagsCompare)) { //Se a tag já existe RestUtils::sendResponse('406', array('data' => 'tagName', 'message' => 'A tag a ser cadastrada já existe.')); } //Conexão $sql = new DataBase(); $sql->connect(); //Adiciona a tag no banco $sql->query("INSERT INTO tags(name, profile_id) VALUES ('" . ucfirst(trim(convertToUnicode($data['tagName']))) . "','" . CurrentUser::getId() . "')"); //Termina execução com sucesso $sql->close(); RestUtils::sendResponse('201'); break;