Save, edit & update languages in one time

alxwm 0 Tallied Votes 95 Views Share

I wont describe whats here, just figure it out yerself, enjoy =)

// Mass Language Manager
	function SaveAll() {
		// adding
		$_REQUEST['val'] = array_unique($_REQUEST['val']);
		foreach ($_REQUEST['val'] as $key => $keyValue) {
			if (!$keyValue OR !strlen(join('',$_REQUEST['new'][$key]))) continue;
			if (!($keyValue = alnum($keyValue))) continue;
			if (mb_strlen($keyValue)>25 OR $this->checkForKey($keyValue)) continue;
			foreach ($_REQUEST['new'] as $i => $arrLangVal) {
				foreach ($arrLangVal as $lang => $value) {
					if ($value) {
						$_REQUEST['new'][$i][$lang] = addslashes($value);
					} else {
						foreach ($arrLangVal as $l => $v) {
							if ($arrLangVal[$l]) {
								$_REQUEST['new'][$i][$lang] = addslashes($v);
							}
						}
					}
				}
			}
			$strSql = 'INSERT INTO '.$this->strTable.' 
				(val, '.join(',',array_keys($_REQUEST['new'][$key])).') 
			VALUES
				(\''.$keyValue.'\', \''.join('\',\'',array_values($_REQUEST['new'][$key])).'\')';
			$this->objDB->query($strSql);
		}
		
		// deleting
		$delArr = array();
		if (count($_REQUEST['del'])) {
			foreach ($_REQUEST['del'] as $keyVal => $Y) {
				if ($Y!='Y') continue;
				$delArr[] = $keyVal;
				$strSql = 'DELETE FROM '.$this->strTable.' WHERE val=\''.$keyVal.'\'';
				$this->objDB->query($strSql);
			}
		}
		
		// updating
		if (!count($_REQUEST['old'])) return;
		foreach ($_REQUEST['old'] as $keyValue => $arrLangVal) {
			if (in_array($keyValue,$delArr) OR !strlen(join('',$_REQUEST['old'][$keyValue]))) continue;
			$arrUpdateValues = array();
			foreach ($arrLangVal as $lang => $value) {
				if ($value) {
					$arrUpdateValues[] = $lang.'=\''.addslashes($value).'\'';
				} else {
					foreach ($arrLangVal as $lang => $value) {
						if ($arrLangVal[$lang]) {
							$arrUpdateValues[] = $lang.'=\''.addslashes($value).'\'';
						}
					}
				}
			}
			$strSql = 'UPDATE '.$this->strTable.' 
				SET '.join(',',$arrUpdateValues).'
			WHERE
				val = \''.$keyValue.'\'';
			$this->objDB->query($strSql);
		}
	}
Dani 4,312 The Queen of DaniWeb Administrator Featured Poster Premium Member

I don't get it? ... and I'm a PHP programmer. It looks like the function is part of a class that you aren't showing us. What are we saving??

nav33n 472 Purple hazed! Team Colleague Featured Poster

Sorry ! What does this code snippet do btw ?

Shanti C 106 Posting Virtuoso

I dont underastand what u wrote??

anmurthy 0 Newbie Poster

i dont understand wat u worte?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.