Skip to content

Commit e5a1fa0

Browse files
committed
2 Versions for all OXID Versions
1 parent 0d8af1f commit e5a1fa0

File tree

3 files changed

+255
-0
lines changed

3 files changed

+255
-0
lines changed
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
/* sponsored by suabo.de */
3+
class rescueimg extends oxUBase {
4+
5+
protected $_aArticleWithImage;
6+
7+
public function render() {
8+
if($this->getUser()->oxuser__oxrights->value != 'malladmin') { echo "Du bist kein Admin, oder?";exit();}
9+
$aMatch = glob("out/pictures/master/1/*.*");
10+
$iActPicCnt = oxDb::getDb()->getOne("SELECT COUNT(oxartnum) FROM oxarticles WHERE (oxpic1!='' AND oxpic1!='nopic.jpg');");
11+
?>
12+
<html>
13+
<body><head><meta charset="utf-8">
14+
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
15+
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
16+
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
17+
<style>
18+
body, html {padding:25px 10px 0;margin:0;font-family:Verdana;}
19+
h1 {position:fixed;top:0px;left:0px;width:100%;padding:5px 10px;background:menu;box-shadow:0px 2px 3px #ccc;margin:0;font:16px Verdana;line-height:25px;height:25px;}
20+
h2 {position:fixed;top:0px;right:50px;padding:5px 10px;margin:0;font:16px Verdana;line-height:25px;height:25px;}
21+
#footer {position:fixed;bottom:0px;left:0px;width:100%;padding:5px 10px;background:menu;box-shadow:0px 2px 3px #ccc;margin:0;font:16px Verdana;line-height:25px;height:25px;}
22+
a {text-decoration:none;color:#666;}
23+
a.btn {text-decoration:none;color:white;font-weight:bold;font-size:14px;}
24+
.btn {padding:4px 10px;border:1px solid #666;border-radius:5px;background:#333;box-shadow:2px 2px 3px #ccc;}
25+
.box {width:375px;float:left;padding:5px;border:1px solid #666;border-radius:5px;background:#fff;}
26+
.imgbox {width:600px;min-height:150px;padding:10px;border:1px solid #666;border-radius:5px;background:#ccc;box-shadow:2px 2px 3px #ccc;}
27+
img {max-width:200px;max-height:200px;float:left;margin-right:10px;}
28+
img#info {max-width:50px;max-height:50px;float:left;margin-right:10px;}
29+
label {display:inline-block;min-width:130px;}
30+
input[type="text"] {width:250px;}
31+
input.btn {color:white;font-weight:bold;cursor:pointer;font-size:14px;}
32+
</style>
33+
34+
<script>
35+
$(function() {
36+
$( "#artnum" ).autocomplete({
37+
source: "/?cl=rescueimg&fnc=ajaxSearchArtNum",
38+
minLength: 2,
39+
select: function( event, ui ) {
40+
$(this).val(ui.item);
41+
$('#artid').val(ui.item.id);
42+
$('#artnum').val(ui.item.artnum);
43+
$('#label').html(ui.item.label);
44+
$('#info').attr('src', '/out/pictures/'+ui.item.image);
45+
console.log(ui.item.image);
46+
if(ui.item.image != '' && ui.item.image != '1/nopic.jpg') $('.box').css('background', 'green');
47+
else $('.box').css('background', 'red');
48+
}
49+
});
50+
$( "#title" ).autocomplete({
51+
source: "/?cl=rescueimg&fnc=ajaxSearchTitle",
52+
minLength: 2,
53+
select: function( event, ui ) {
54+
$(this).val(ui.item);
55+
$('#artid').val(ui.item.id);
56+
$('#label').html(ui.item.label);
57+
$('#artnum').val(ui.item.artnum);
58+
$('#info').attr('src', '/out/pictures/'+ui.item.image);
59+
if(ui.item.image != '' && ui.item.image != '1/nopic.jpg') $('.box').css('border-color', 'green');
60+
else $('.box').css('border-color', '#666');
61+
}
62+
});
63+
64+
$('#deleteButton').click(function(e) {
65+
e.preventDefault();
66+
if (confirm('Sicher löschen?')) {
67+
$(location).attr('href', e.target);
68+
}
69+
});
70+
});
71+
</script>
72+
73+
</head>
74+
<h1>OXID Bildzuweisungen Wiederherstellen</h1>
75+
<h2>Es sind <? echo $iActPicCnt; ?> / <? echo count($aMatch); ?> Bilder zugewiesen.</h2>
76+
<?if(!$_GET['do'] && !$_POST['do']) { ?>
77+
<a class="btn" href="/?cl=rescueimg&do=startAutoImgageRescue">Automatische Bildrettung starten</a>&nbsp;&nbsp;&nbsp;
78+
<a class="btn" href="/?cl=rescueimg&do=startAdvImgageRescue">manuelle Bildrettung starten</a>
79+
<? } else if($_GET['do']) $this->$_GET['do']();
80+
else if($_POST['do']) $this->$_POST['do']();
81+
?>
82+
<div id="footer">
83+
supported by <a href="http://www.suabo.de" target="_blank">suabo.de</a>
84+
</div>
85+
</body>
86+
</html>
87+
<?
88+
exit();
89+
}
90+
91+
public function ajaxSearchTitle() {
92+
$oArtList = oxNew('oxList');
93+
$oArtList->init('oxarticle');
94+
$oArtList->SelectString("SELECT oxid, oxtitle, oxartnum, oxpic1 FROM oxarticles WHERE oxtitle LIKE '%{$_GET['term']}%' AND oxactive='1';");
95+
$aArticles = array();
96+
foreach($oArtList as $oArticle) {
97+
$aArticle['id'] = $oArticle->oxarticles__oxid->value;
98+
$aArticle['label'] = $oArticle->oxarticles__oxtitle->value." - ".$oArticle->oxarticles__oxartnum->value;
99+
$aArticle['artnum'] = $oArticle->oxarticles__oxartnum->value;
100+
$aArticle['image'] = $oArticle->oxarticles__oxpic1->value;
101+
$aArticle['value'] = $oArticle->oxarticles__oxtitle->value;
102+
$aArticles[] = $aArticle;
103+
104+
}
105+
echo json_encode($aArticles);
106+
exit();
107+
}
108+
109+
public function ajaxSearchArtNum() {
110+
$oArtList = oxNew('oxList');
111+
$oArtList->init('oxarticle');
112+
$oArtList->SelectString("SELECT oxid, oxtitle, oxartnum, oxpic1 FROM oxarticles WHERE oxartnum LIKE '%{$_GET['term']}%' AND oxactive='1';");
113+
$aArticles = array();
114+
foreach($oArtList as $oArticle) {
115+
$aArticle['id'] = $oArticle->oxarticles__oxid->value;
116+
$aArticle['label'] = $oArticle->oxarticles__oxartnum->value." - ".$oArticle->oxarticles__oxtitle->value;
117+
$aArticle['artnum'] = $oArticle->oxarticles__oxartnum->value;
118+
$aArticle['image'] = $oArticle->oxarticles__oxpic1->value;
119+
$aArticle['value'] = $oArticle->oxarticles__oxartnum->value;
120+
$aArticles[] = $aArticle;
121+
}
122+
echo json_encode($aArticles);
123+
exit();
124+
}
125+
126+
public function startAdvImgageRescue() {
127+
$aMatch = glob("out/pictures/master/1/*.*");
128+
?>
129+
<form action="/index.php" method="POST">
130+
<?
131+
$iImgCnt = 0;
132+
if($iImgCnt = $_GET['jmpimg']) { for($i=0;$i<$iImgCnt;$i++) unset($aMatch[$i]); }
133+
134+
foreach($aMatch as $sImageName) {
135+
$iImgCnt++;
136+
$aPathInfo = pathinfo($sImageName);
137+
$sArtNum = oxDb::getDb()->getOne("SELECT oxartnum FROM oxarticles WHERE oxpic1='".$aPathInfo['basename']."';");
138+
if($sArtNum) {
139+
$this->_aArticleWithImage[] = $sArtNum;
140+
} else {
141+
?>
142+
<div class="imgbox">
143+
<img src="<? echo $sImageName; ?>" alt="">
144+
<div>
145+
<label>Bildname:</label> <? echo $aPathInfo['basename']; ?><br>
146+
<div class="box" style="margin-top:10px;">
147+
<label>Ausgewähltes Produkt:</label><br><br>
148+
<img id="info" src="" alt="">
149+
<strong id="label"></strong><br>
150+
</div>
151+
<div style="float:left;margin-top:10px;width:390px;">
152+
<input type="hidden" name="cl" value="rescueimg">
153+
<input type="hidden" name="do" value="saveImageToArticle">
154+
<input type="hidden" id="artid" name="id" value="">
155+
<input type="hidden" name="image" value="<? echo $sImageName; ?>">
156+
<label>Artikelnummer:</label> <input id="artnum" type="text" name="artnum" value=""><br>
157+
<label>Titel:</label> <input id="title" type="text" name="title" value=""><br>
158+
<br>
159+
</div>
160+
<div style="float:left;margin-top:10px;width:100%;">
161+
<a class="btn" href="/?cl=rescueimg&do=startAdvImgageRescue&jmpimg=<? echo $iImgCnt; ?>">Bild überspringen</a>&nbsp;&nbsp;&nbsp;<a id="deleteButton" class="btn" href="/?cl=rescueimg&do=deleteImage&jmpimg=<? echo $iImgCnt; ?>&imgpath=<? echo $sImageName; ?>">Bild löschen</a><input class="btn" type="submit" value="Bild zu Artikel Speichern" style="float:right;">
162+
</div>
163+
</div>
164+
<div style="clear:both;"></div>
165+
</div>
166+
<?
167+
break;
168+
}
169+
}
170+
?>
171+
</form>
172+
<?
173+
}
174+
175+
public function deleteImage() {
176+
$sImagePath = $_GET['imgpath'];
177+
$iJumpToImage = $_GET['jmpimg'];
178+
if($sImagePath && file_exists($sImagePath)) {
179+
unlink($sImagePath);
180+
}
181+
?>
182+
<div class="imgbox">
183+
<strong>Bildpfad:</strong> <? echo $sImagePath; ?><br>
184+
Das Bild wurde erfolgreich gelöscht.<br>
185+
<br><br><br>
186+
<a class="btn" href="/?cl=rescueimg&do=startAdvImgageRescue&jmpimg=<? echo ($iJumpToImage-1); ?>" style="float:right;">Weiter mit nächstem Bild</a>
187+
</div>
188+
<?
189+
}
190+
191+
public function saveImageToArticle() {
192+
$oArticle = oxNew('oxarticle');
193+
if($oArticle->load($_POST['id'])) {
194+
$aPathInfo = pathinfo($_POST['image']);
195+
$oArticle->oxarticles__oxpic1->value = $aPathInfo['basename'];
196+
$oArticle->save();
197+
?>
198+
<div class="imgbox">
199+
<img src="/out/pictures/<? echo $oArticle->oxarticles__oxpic1->value; ?>" alt="">
200+
<div style="float:left;width:330px;margin-bottom:40px;">
201+
<label>Artikelnummer:</label><? echo $oArticle->oxarticles__oxartnum->value; ?><br>
202+
<strong><? echo $oArticle->oxarticles__oxtitle->value; ?></strong><br>
203+
Bild wurde erfolgreich gespeichert.
204+
</div>
205+
<a href="/?cl=rescueimg&do=startAdvImgageRescue" class="btn" style="float:right;">Weiter mit nächstem Bild</a>
206+
<div sytle="clear:both;"></div>
207+
</div>
208+
<?
209+
}
210+
}
211+
212+
public function startAutoImgageRescue($blSaveFoundImages = true) {
213+
$oArtList = oxNew('oxList');
214+
$oArtList->init('oxarticle');
215+
$oArtList->SelectString("SELECT oxid, oxartnum, oxpic1 FROM oxarticles WHERE (oxpic1='' OR oxpic1='nopic.jpg') AND oxactive='1';");
216+
217+
foreach($oArtList as $oArticle) {
218+
if( $sImagePath = $this->searchImage($oArticle->oxarticles__oxartnum->value) ) {
219+
$aPathInfo = pathinfo($sImagePath);
220+
echo "Artnum: ". $oArticle->oxarticles__oxartnum->value." Image: ".$oArticle->oxarticles__oxpic1->value." Masterbild gefunden: ";
221+
echo $sImagePath."<br>";
222+
echo "<br>";
223+
if($blSaveFoundImages) {
224+
$oArticle->oxarticles__oxpic1->value = $aPathInfo['basename'];
225+
$oArticle->save();
226+
}
227+
}
228+
}
229+
}
230+
231+
private function searchImage($sArtNum) {
232+
$aMatch = glob("out/pictures/master/1/".$sArtNum."*");
233+
if(count($aMatch) === 1) {
234+
//we got one
235+
return $aMatch[0];
236+
} else if(count($aMatch) > 1) {
237+
//we take the last one, seams to fit best here :D
238+
return $aMatch[count($aMatch)-1];
239+
}
240+
}
241+
}
242+
?>

README.TXT

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Installation
2+
-------------
3+
4+
1. Kopieren Sie das copy_this Verzeichnis in Shop-Root.
5+
Fertig.
6+
7+
Nutzung der Bildrettung
8+
-----------------------
9+
10+
Melden Sie sich im Frontend als Administrator an.
11+
Nach der Installation können Sie das Tool wie folgt aufrufen:
12+
13+
http://www.ihre-domain.de/?cl=rescueimg

0 commit comments

Comments
 (0)